Zapatero said Spanish troops would leave Iraq by June 30, a central theme of his election campaign.
He said the troops would be withdrawn if the "situation had not changed," referring to the planned transfer of sovereignty of power later this year.
The socialist victory not only ended Spanish conservatives' eight-year reign, but dealt a blow to U.S. President George Bush's policies for combating Islamic terrorism, the Wall Street Journal said.
Sunday's elections were overshadowed by the memory of Thursday's terror attacks in Madrid when simultaneous commuter train bombings killed 200 people. One of five men arrested so far has links to the al-Qaida terror group.
The socialists won 163 seats in the 350-seat parliament Sunday after gaining nearly 3 million more votes than it won in the elections in 2000. The conservative Popular Party lost 900,000 votes, and will be the second party in congress with 148 seats, the Financial Times said.
The socialists do not have a majority, and will have to govern with the support of small regional parties.
Celebrity Couples of 2014 [PHOTOS]