(Adds missing word in quote, fixes first name in paras 12 & 13)
* Prime minister convinced defence minister to change mind
* Ministries to be blocked until government quits -gunmen
* Law banning ex-Gaddafi officials could cripple government
By Ghaith Shennib and Jessica Donati
TRIPOLI, May 7 Libya's defence minister quit on Tuesday only to reverse himself soon afterward, the prime minister's office said, and gunmen pledged to keep two ministries under siege in a crisis pointing to a security breakdown in the young democracy.
Armed groups seized the Foreign Ministry on April 28 and ringed the Justice Ministry two days later to push parliament into passing a law barring anyone who held a senior position under late dictator Muammar Gaddafi from public service.
The Tripoli parliament did precisely that on Sunday but the gunmen have refused to disperse, insisting the entire government step down and prompting Defence Minister Mohammed al-Barghathi to resign in frustration at the feebleness of security services.
"I will never be able to accept that politics can be practiced by the power of weapons ... This is an assault against the democracy I have sworn to protect," Barghathi, who was an air force commander in the Gaddafi era, told a news conference.
Two hours later the prime minister's office said Barghathi had agreed to stay on the job. "The prime minister (Ali Zeidan) persuaded that this was not the right time," a source in Zeidan's office told Reuters.
He said Barghathi had complained that some of the gunmen were seen using army equipment and "he could not accept that ... I'm sure he did feel powerless ... But the government has been very persistent in resisting (these gunmen) peacefully."
Many of the armed men were instrumental in ending Gaddafi's 42-year rule in 2011. But they have declined to vacate the capital Tripoli and various militias and tribes now control large swathes of the vast, oil-producing North African country.
The already shaky central government could be rendered largely dysfunctional if the new law is fully implemented to oust senior ministers and officials seasoned in public service, diplomats and analysts fear.
However, leaders of the armed groups besieging the ministries said that they would not fall back unless the entire government resigned.
"Our demand was, from the beginning, for the General National Congress (parliament) to withdraw its confidence from the government," said Wissam Bin Majid, a leader of one of the armed groups at the Foreign Ministry.
"It does not matter whether the political isolation law is implemented after a month or a year, this government must step down now," Majid said.
"This would send the wrong message that the power of the gun rules supreme, that the government will cave to pressure under the threat of violence," said Anthony Skinner, Middle East and North Africa director at risk consultancy Maplecroft.
"There is a risk he (Barghathi) will have to resign anyway but the government doesn't want to be seen to be forced into a knee-jerk reaction... (Still), all this shows a lack of control and a feeling that he can't do his job properly."
Barghathi's announced resignation was accompanied on Tuesday by local media reports that other ministers and the army chief of staff had also stepped down. Zeidan's office denied this.
Diplomats said that in agreeing to vote under duress from the streets, parliament may have effectively strengthened armed groups who cut a higher profile than state security forces.
On Monday a parliamentary spokesman said it was beyond the government's capability to break the siege of the two ministries and that it would be up to the militiamen now to leave as promised. (Writing by Jessica Donati; Editing by Mark Heinrich)
Our top photos from the last 24 hours.