Casting their ballots in the wake of the worst terrorist attacks in Spain's history, Spaniards voted Sunday to oust the ruling Popular Party of outgoing Prime Minister Jose Maria Aznar, blaming his staunch backing of the U.S. war in Iraq for the bombings that left 200 people dead and more than 1500 injured.

The headquarters of the Spanish Socialist Workers party were caught up Monday night in a delirium of celebrations of an upset victory over the ruling Popular Party.

In a stunning upset, voters decided to give power to the opposition Socialist Party, whose leader, Jose Luis Rodriguez Zapatero, has promised to immediately withdraw Spain's 1,300 troops from Iraq, unless the United Nations approves their presence.

With a majority of the vote counted, the Socialists won 43 percent of the of the ballots cast. That means the Socialists will occupy 164 seats of the 350 seats in parliament, with 148 seats going to the Popular Party. The results would leave the Socialists short of an absolute majority, but they can rule by forming a coalition with smaller regional parties.

After observing a minute of silence in memory of the victims of Thursday attacks, Mr. Zapatero made a brief acceptance speech.

The Socialist leader promised to bring about a tranquil change for the benefit of everyone. He also promised to rule with humility saying that power would not change him. He also vowed to make the fight against terrorism his immediate priority.

The results were a blow to outgoing Prime Minister Jose Maria Aznar who was hoping to hand over power to his hand-picked successor, Mariano Rajoy, who promised to continue Mr. Aznar's pro-American foreign policy.

Earlier polls taken before the terrorists attacks showed Mr. Rajoy and the Popular Party well ahead of the Socialists.

But Thursday's terrorist attacks, changed all that. More than 12 million Spaniards took to the streets of Spain's major cities in protest, as mounting evidence of those responsible for the bombing pointed to Islamic extremists, not the country's violent Basque separatist group, or ETA.

On Saturday the arrest of three Moroccans and two Indians in connection to the attacks and the discovery of a videotape of a self-described head of al-Qaida's military wing in Europe fanned growing skepticism over the government's belief that ETA was responsible. The man on the tape said Thursday's train attacks were a response Spain's "collaboration with the criminal Bush and his allies."