British troops are due to be withdrawn from Iraq next year
Iraqi MPs have authorised the government to sign agreements allowing British and other non-US troops to stay on in the country after 2008.
They approved the move after speaker Mahmoud Mashhadani resigned at the demand of Shia and Kurdish parties, ending a political impasse.
The US earlier struck its own security pact to keep troops in Iraq to 2011.
Foreign troops' UN mandate runs out on 31 December, after which they require a new legal basis to be in Iraq.
Most of the non-US foreign troops currently deployed in Iraq are British.
The British troops are due to leave Iraq by the end of July next year, UK Prime Minister Gordon Brown said last week.
Other foreign, non-US troops include Australians and Romanians.
El Salvador announced on Tuesday it would end its military presence in Iraq on 31 December.
Salvadorean President Elias Antonio Saca pointed to the "lack of a UN resolution" as the reason for withdrawing the 200-strong contingent.
Tuesday's vote ends a week of uncertainty over the legal status of British, Australian and other foreign troops in Iraq, BBC defence correspondent Caroline Wyatt reports from Basra.
NON-US FORCES IN IRAQ
UK - 4,100
Australia - 1,000
Romania - 500
El Salvador - 200
Estonia - 40
Reza Jawad Taqi, an MP from the main pro-government Shia bloc, told the BBC the resolution had been passed by an overwhelming majority in the Iraqi parliament.
That should clear the way for the Iraqi government to sign bilateral deals with Britain and the other nations whose troops will be staying on in Iraq into next year, our correspondent says.
She adds that the passing of the resolution will come as a relief to the British government and the UK's armed forces, who would have faced a legal limbo over their right to remain in Iraq to complete their mission had the agreement not been voted in on time.
'World's worst parliament'
Turmoil over the speaker had led to a vote on the extension of the mandate - scheduled for Monday - being postponed.
Mr Mashhadani had been under pressure to quit since failing to control a shouting match over the journalist who threw his shoes at US President George W Bush earlier this month.
"I announce that I'm resigning from my position as parliament speaker in the interests of the people," he said in a speech to MPs.
The outgoing speaker, a member of the Sunni minority, has long been a controversial figure, blaming many of Iraq's troubles on the US military presence.
But when MPs debated the shoe incident, he enraged Shia and Kurdish lawmakers by using crude language and describing Iraq's assembly as "the worst parliament in the world".
This week he also insulted two female Iraqi MPs.
Meanwhile, the journalist arrested after the attack on Mr Bush is due to go on trial on 31 December, his brother and a judge said.
Muntadar al-Zaidi is accused of "aggression against a foreign head of state" over the 14 December incident.