BAGHDAD - The Iraqi parliament approved a security agreement yesterday that allows British troops and other non-U.S. foreign forces to stay after a U.N. mandate expires Dec. 31.

The vote followed the resignation of the volatile parliament speaker, Mahmoud al-Mashhadani, who had offered to quit the post last week when lawmakers loyal to the anti-U.S. Shiite cleric Muqtada al-Sadr refused to discuss the security agreement.

Many had written off Mashhadani's gesture as a reaction to parliament's often-chaotic operations. Mashhadani, a Sunni, later retracted his offer. But Shiite and Kurdish lawmakers said he had insulted parliament and insisted he quit.

In exchange for his resignation, Shiites and Kurds agreed that another lawmaker from the main Sunni political bloc, the Iraqi Accordance Front, could be named to replace him. And they agreed to vote on the security pact - but only after Mashhadani had agreed to quit.

Then, they publicly praised him for presiding over parliament since spring 2006 and called his resignation an administrative matter.

Even some of Mashhadani's own coalition hoped that the parliament would be run in a more orderly manner after the departure of the voluble speaker.

Mashhadani, who remains a member of parliament, was controversial throughout his tenure as speaker.

Sunni lawmakers said he had vowed to reform his behavior in summer 2007, when his bodyguards allegedly beat up a Shiite lawmaker after a verbal altercation. He was briefly dismissed over the incident, then reinstated.

"He was rough with everyone. He used vulgar language and was directing insults at everyone without any exceptions," said Selim Abdullah Jabouri, spokesman for the Iraqi Accordance Front, of which Mashhadani is a member. "The blocs found that this phenomenon was too frequent and that it was not acceptable."

Mashhadani also praised Iraqi journalist Muntadhar al-Zeidi, who rocketed to fame a week ago when he hurled his shoes at President Bush during a Baghdad news conference. Zeidi, who has become a folk hero, is scheduled for trial Dec. 31 on charges of attacking a foreign head of state.

After the speaker's resignation, parliament quickly approved the security agreement, which calls for all British troops to withdraw by July 31. The date fits with last week's announcement by British Prime Minister Gordon Brown that his country's military operations in southern Iraq would be completed by May 31 and that a full withdrawal would be finished two months later.

Britain welcomed the pact, embassy spokesman Jawwad Syed said. He said London was prepared to leave 400 officers to train the Iraqi navy if Iraq requested it.

The agreement also applies to the other remaining non-U.S. foreign forces in Iraq and to NATO.

Only Albania, Australia, Estonia and El Salvador still have forces in Iraq of an alliance that totaled more than three dozen countries when U.S.-led troops invaded in 2003. Yesterday, El Salvador President Tony Saca said he would withdraw Salvadoran troops, which total 200, after Dec. 31.