Spanish Prime Minister Jose Luis Rodriguez Zapatero said he had given orders for Spain's 1,400 troops in Iraq to come home as soon as possible.

Zapatero made the surprise announcement in a televised statement a day after being sworn in as prime minister following his Socialist party's upset victory in a March 14 general election held in the shadow of the Madrid train bombings.

Zapatero had said previously he would pull out the troops if the United Nations did not take charge in Iraq by June 30.

He said he was acting now because there was no prospect of a UN resolution being adopted that met Spain's conditions.

A government source said the withdrawal operation would take "at least a month and a half to two months" and declined to say when it would start.

The troops, now numbering 1,400, will be moved out to Kuwait by bus in a complex operation, the source said.

Zapatero's decision creates more problems for the United States whose forces are locked in the fiercest fighting in Iraq since last year's war toppled Saddam Hussein.

US combat casualties in Iraq topped 500 on Sunday.

Spanish bases in Diwaniya and Najaf in south-central Iraq have come under sporadic attack during the recent upsurge of violence there and several Spanish troops have been wounded.

Zapatero, a strong opponent of the US-led war, said he had given new Defence Minister Jose Bono "the order to do what is necessary for the Spanish troops in Iraq to come home in the shortest possible time and the greatest possible safety".

About 1,000 people gathered in central Madrid tonight for a noisy celebration of the news.

"If you kill people overseas, they'll kill you here. It was illegal. We Spaniards don't want war," said administrator Esteban Fernandez, 41, drawing a link between the Iraq war and last month's Madrid bombings that killed 191 people.

The White House had hoped Zapatero would reconsider his campaign pledge if the United Nations took a bigger role in Iraq.

But Zapatero said there was no indication there would be "a substantial change in the political and military situation in Iraq" by June 30.

The United States expects other nations with forces in Iraq to reassess their position after Spain's decision, President George W. Bush's national security adviser said today.

Condoleezza Rice, speaking on ABC's "This Week" before the decision was announced in Madrid, said: "We have 34 countries with forces on the ground. I think there are going to be some changes."

Zapatero called an urgent meeting of parliament to brief legislators. The session is expected to be held on Tuesday.

Spanish soldiers in Iraq were taken by surprise.

"We found out about the news through the media ... It's already night here, so I don't think the news will have reached many people," a Spanish officer in Diwaniya, south of Baghdad, told state radio.

Voters swept former Prime Minister Jose Maria Aznar's pro-US Popular Party from power in the March election.

Aznar sent the Spanish troops to Iraq after the war, even though the US intervention was deeply unpopular with most Spaniards.

The elections were held three days after the bombing of four Madrid commuter trains.

A videotape purportedly from al Qaeda said the attacks were a response to Spanish support of US-led military operations in Iraq and Afghanistan.