Militias allied with a former Libyan general staged a brazen attack on Libya’s parliament on Sunday and declared it dissolved, in some of the worst fighting the capital has seen since the 2011 revolution.

By Sunday night, those forces announced that the elected General National Congress was being replaced by an existing constitutional drafting committee. It was far from certain that the order would be observed. But the power grab threatened to send Libya hurtling into a full-blown civil war.

Tripoli residents and journalists reported heavy fighting, including rocket attacks and gunfights, in several central neighborhoods. Dozens of vehicles mounted with antiaircraft guns could be seen speeding toward the center of the capital from a southeastern suburb. Plumes of black smoke rose over the city.

It was unclear whether ex-general Khalifa Haftar commanded sufficient force to prevail in the showdown in Tripoli — the latest chapter in a struggle for power, land and resources that has raged in this oil-rich country since the fall of longtime dictator Moammar Gaddafi. The central government has struggled unsuccessfully to rein in scores of militias that emerged from the anti-Gaddafi uprising.

“In Libya, there really isn’t a party on the ground that is more powerful than the other,” said Essam Gheriyani, a prominent businessman.

The Associated Press quoted hospital officials as saying that two people were killed and more than 60 were wounded in the fighting, which occurred two days after Haftar’s forces launched an assault on Islamist militias in the eastern city of Benghazi, leaving 70 dead.

Libyan news media reported that Haftar’s militia members had also kidnapped several national lawmakers Sunday. And rumors circulated that the justice minister had narrowly survived an assassination attempt.

Reached by phone, the justice minister, Salah Merghani, sounded shaken but would not comment on the reports. “My colleagues and I are okay. I can’t really talk. Thank you,” he said.

In an ominous sign, militias from the coastal city of Misrata were en route to Tripoli on Sunday night, said Anwar Salwan, a powerful local leader from the city about 110 miles east of the capital.

Haftar is a mysterious general-turned-opposition-leader who sought exile in the United States in the 1980s and lived for years in Falls Church, Va. He returned to Libya during the 2011 uprising.

Gen. Mokhtar Farnana, speaking for Haftar’s forces, the so-called Libyan National Army, said on Libyan television Sunday that the country’s 60-member constituent assembly, elected this year to draft Libya’s new constitution, would replace parliament, according to the AP. He said Libya’s central government would continue to act on an emergency basis.

“We announce to the world that the country can’t be a breeding ground or an incubator for terrorism,” said Farnana, according to the AP.

But some members of Libya’s government said they would ignore the demands by Haftar’s forces.

“The government condemns the expression of political opinion through the use of armed force,” Merghani said in a statement, the AP reported.

In recent months, Libya’s militias have roughly divided into two groups. One includes Islamist militias in Benghazi, joined by allies from Misrata. The other is a diverse group of more-liberal politicians, Gaddafi-era military officers and tribal militias from Tripoli and the western mountains.

Both sets of forces hold positions, or at least allies, in the central government and in parliament, and have received funding and resources from the state.

On Sunday, two Tripoli militias who form part of the anti-Islamist grouping stormed the parliament’s empty headquarters.

The militias — known as the Qaqa and Sawaiq — pledged allegiance to Haftar. As darkness fell over Libya and the country’s political future, it was also unclear where the former general was.

Haftar’s history with U.S.

Haftar is a well-known figure in Libya. He was a military officer who took part in the 1969 coup that brought Gaddafi to power. He later commanded Libyan troops in their war with neighboring Chad, but was taken prisoner by Chadian forces.

In 1988, he broke with Gaddafi and established the Libyan National Army, described as a rebel group based in Chad. Haftar claimed publicly that he had U.S. backing.

In a 2011 interview with CNN, Libya’s former ambassador in Washington, Ali Aujali, who supported the anti-Gaddafi uprising that year, declined to confirm whether the CIA had bankrolled the Libyan rebel group established years earlier by Haftar. But he said, “The Americans know him very, very well.”

He added: “I think working for the CIA for the sake of your national interest is nothing to be ashamed of.”

When The Post asked in 2011 about Haftar’s possible connections to the CIA, a senior intelligence official said the agency policy was not to discuss such issues.

Haftar had struggled unsuccessfully to gain control over Libya’s disparate rebel forces during the early months of the 2011 uprising. After Gaddafi’s ouster, he had gradually faded from the Libyan political scene, until recently.

Some Libyans called Haftar’s assault Sunday a military coup.

But other observers said that that description would lend the forces more legitimacy than they deserve.

“It’s silly to say a military coup, because there is no military,” said Jalal el-Gallal, a former member of Libya’s transitional authority.

Massoud Ali Shalash, a Haftar supporter and a local leader in the western mountain town of Zintan, said the militias had given the government a chance to show it could run the country.

“The Congress is a failure and the government is a failure. The purpose of [Haftar’s] actions was to purify the army and the Congress,” he said.

Salwan, the Misrata leader, said the city’s militias had stopped about 60 miles from Tripoli on Sunday night, to try “to understand more about who is fighting with whom before sending in our forces.”

But “Zintan must be stopped,” he added, referring to the Qaqa brigade’s home town.

Hauslohner reported from Moscow. Erin Cunningham and Lara El Gibaly in Cairo contributed to this report.