President William McKinley could not prevent war with Spain because many Americans were in favor of helping the rebels in Cuba overthrow the Spanish. The media, the sinking of the USS Maine and the Spanish government's slow response to diplomacy put pressure on him to ask Congress to declare war.
Cuban rebels first attempted to gain independence in 1895, a year before McKinley became president. The rebels operated out of the United States and some American private interests provided them with financial backing. The Spanish colonial government quashed the rebellion and put captured rebels in concentration camps, where many died. The newspapers, led by Randolph Hearst, supported the rebel cause and portrayed McKinley as weak for not intervening in Cuba.
Explosions sank the USS Maine and killed 255 men in February of 1898. Americans blamed the Spanish, although the cause turned out to be faulty ammunition on the ship. Though McKinley tried to negotiate a peaceful resolution, Spain did not respond quickly enough, and the demand for war grew too large for McKinley to ignore. In April, Congress declared war on Spain and the Spanish-American War lasted until August. Following the war, the United States pursued foreign-affairs policies historians now view as imperialist.