Given the reference text about the Spanish-American war, when and how did the war end?

The Spanish–American War[b] (April 21 – August 13, 1898) began in the aftermath of the internal explosion of USS Maine in Havana Harbor in Cuba, leading to United States intervention in the Cuban War of Independence. The war led to the United States emerging predominant in the Caribbean region, and resulted in U.S. acquisition of Spain's Pacific possessions. It led to United States involvement in the Philippine Revolution and later to the Philippine–American War.

The 19th century represented a clear decline for the Spanish Empire, while the United States went from becoming a newly founded country to being a medium regional power. In the Spanish case, the descent, which already came from previous centuries, accelerated first with the Napoleonic invasion, which in turn would cause the independence of a large part of the American colonies, and later political instability (pronouncements, revolutions, civil wars) bled the country socially and economically. The U.S., on the other hand, expanded economically throughout that century by purchasing territories such as Louisiana and Alaska, militarily by actions such as the Mexican–American War, and by receiving large numbers of immigrants. That process was interrupted only for a few years by the American Civil War and Reconstruction era.

The main issue was Cuban independence. Revolts had been occurring for some years in Cuba against Spanish colonial rule. The United States backed these revolts upon entering the Spanish–American War. There had been war scares before, as in the Virginius Affair in 1873. But in the late 1890s, American public opinion swayed in support of the rebellion because of reports of concentration camps set up to control the populace. Yellow journalism exaggerated the atrocities to further increase public fervor and to sell more newspapers and magazines.

The business community had just recovered from a deep depression and feared that a war would reverse the gains. Accordingly, most business interests lobbied vigorously against going to war. President William McKinley ignored the exaggerated news reporting and sought a peaceful settlement. Though not seeking a war, McKinley made preparations for readiness against one. He unsuccessfully sought accommodation with Spain on the issue of independence for Cuba. However, after the U.S. Navy armored cruiser Maine mysteriously exploded and sank in Havana Harbor on February 15, 1898, political pressures pushed McKinley into a war that he had wished to avoid.

As far as Spain was concerned, there was a nationalist agitation, in which the written press had a key influence, causing the Spanish government to not give in and abandon Cuba as it had abandoned Spanish Florida when faced with a troublesome colonial situation there, transferring it to the U.S. in 1821 in exchange for payment of Spanish debts. If the Spanish government had transferred Cuba it would have been seen as a betrayal by a part of Spanish society and there would probably have been a new revolution. So the government preferred to wage a lost war beforehand, rather than risk a revolution, opting for a "controlled demolition" to preserve the Restoration Regime.

On April 20, 1898, McKinley signed a joint Congressional resolution demanding Spanish withdrawal and authorizing the President to use military force to help Cuba gain independence. In response, Spain severed diplomatic relations with the United States on April 21. On the same day, the United States Navy began a blockade of Cuba. Both sides declared war; neither had allies.

The 10-week war was fought in both the Caribbean and the Pacific. As United States agitators for war well knew, United States naval power would prove decisive, allowing expeditionary forces to disembark in Cuba against a Spanish garrison already facing nationwide Cuban insurgent attacks and further devastated by yellow fever. The invaders obtained the surrender of Santiago de Cuba and Manila despite the good performance of some Spanish infantry units, and fierce fighting for positions such as El Caney and San Juan Hill. Madrid sued for peace after two Spanish squadrons were sunk in the battles of Santiago de Cuba and Manila Bay, and a third, more modern fleet was recalled home to protect the Spanish coasts.

The war ended with the 1898 Treaty of Paris, negotiated on terms favorable to the United States. The treaty ceded ownership of Puerto Rico, Guam, and the Philippines from Spain to the United States and granted the United States temporary control of Cuba. The cession of the Philippines involved payment of $20 million ($650 million today) to Spain by the U.S. to cover infrastructure owned by Spain.

The Spanish–American War brought an end to almost four centuries of Spanish presence in the Americas, Asia, and the Pacific. The defeat and loss of the Spanish Empire's last remnants was a profound shock to Spain's national psyche and provoked a thorough philosophical and artistic reevaluation of Spanish society known as the Generation of '98. The United States meanwhile not only became a major power, but also gained several island possessions spanning the globe, which provoked rancorous debate over the wisdom of expansionism.

The Spanish-American war ended on August 13, 1898 with the 1898 Treaty of Paris. The treaty ceded ownership of Puerto Rico, Guam, and the Philippines from Spain the to the United States.