The US administrator in Iraq has said Iraqi security forces will not be able to protect the country by the 30 June deadline for handing power to Iraqis.
The US says local Iraqi forces cannot quell the violence alone
Paul Bremer said recent attacks by insurgents showed Iraq needed help to deal with continuing security threats.
But Spain's new prime minister has said he wants Spain's troops out of Iraq "as soon as possible".
Soon after the announcement, radical Shia cleric Moqtada Sadr told followers to stop attacking Spanish troops.
The US has said it is prepared for other coalition members to reassess their role in the country.
Washington's National Security Adviser Condoleezza Rice said: "I think there are going to be some changes."
The US-led forces in Iraq said the situation in the country was the quietest for weeks, although a tense stand-off is continuing in the holy city of Najaf between US forces and supporters of radical Shia cleric Moqtada Sadr.
In the capital, Baghdad, the coalition has closed various sections of highways connecting Baghdad from the north, west and south "until Iraqi engineers
and coalition forces can repair them".
According to a statement from the US Central Command: "The safety and security for public travel is the primary reason for the closures."
Nada Doumani, spokeswoman for the International Committee of the Red Cross delegation in Iraq, told BBC News Online the closures had caused huge traffic jams in the city.
On Monday, a mortar reportedly landed in the grounds of the Swedish embassy in the capital.
Police have said no-one was injured in the attack.
The embassy has been closed since 1991, but is guarded by an Iraqi caretaker.
Spanish Prime Minister Jose Luis Rodriguez Zapatero said he had decided to recall the 1,300 Spanish soldiers based in Iraq, because he could not ignore what he called the will of the Spanish people.
Spain's foreign minister told his Egyptian counterpart the pull-out would be "within 15 days", the Egyptian foreign ministry said in a statement.
MAIN FOREIGN TROOPS IN IRAQ
The BBC's Katya Adler in Madrid says military sources there say the pull-out is more likely to take one or two months because of operational requirements.
White House spokesman Ken Lisaius said the US expected Spain to "implement their decision in a co-ordinated, responsible and orderly manner".
The US earlier condemned the decision, saying it was giving in to terrorism.
The BBC's Dominic Hughes in Baghdad says that with the US saying it needs thousands of extra troops on the ground in Iraq, the withdrawal of the Spanish forces will clearly be felt.
Speaking on ABC's This Week programme, before Madrid announced its decision, Ms Rice said: "We know that there are others who are going to have to assess how they see the risk."
"We have 34 countries with forces on the ground. I think there are going to be some changes."
The BBC's Michael Buchanan in Washington says that the US had been expecting the Spanish decision and therefore its response has been markedly low-key.
Militarily, the loss of 1,300 troops is not too much of a problem, our correspondent says - much more damaging will be the political fallout.
The true impact of Spain's withdrawal will be political not military
The loss of any member will put a dent in President George W Bush's image of the "coalition of the willing" and will create concerns of a possible domino effect among other countries with troops stationed in Iraq, he says.
There have been media reports that Portugal could soon follow Spain and it is already known that Kazakhstan will not be replenishing its troop contingent when its soldiers finish their current tour of duty in Iraq.
But although this and other setbacks, such as the spiralling hostage crisis and mounting number of US deaths in Iraq, will have taken their toll on US public opinion, our correspondent believes that the White House will remain resolute in its plan to stay the course in Iraq.