Libya's highest court has ruled that general elections held in June were unconstitutional and that the country's parliament and government, which resulted from that vote, should be dissolved.

The development further deepened the rift in the politically divided Libya, which has been mired in months-long deadly clashes between armed groups who have been fighting for the control of the oil-rich African nation.

The political turmoil has left the country with two rival parliaments and governments.

The Supreme Constitutional Court handed down the ruling in the capital, Tripoli, which is controlled by powerful militias from the western coastal city of Misrata.

Analysis: A proxy struggle being waged in Libya

The militias took over Tripoli from rival armed groups in August after their political allies lost a June parliamentary elections. They revived an earlier parliament that ran the country before the latest elections.

The elected parliament was forced to leave the capital and convene in the far eastern city of Tobruk near the border with Egypt.

The ruling essentially declared illegal a March amendment to the country's transitional constitution that allowed the June elections to take place. Thus, the ruling also rendered the parliament and government that resulted from that vote illegal.

Al Jazeera's Mahmoud Abdul-Wahed, reporting from the capital, said supporters of the Tripoli-based legislature gathered in the city to celebrate the court decision.

In Misrata, rallies were held, complete with fireworks, to celebrate the ruling. Saleh al-Makhzoum, the deputy speaker of the Tripoli-based parliament hailed the ruling as a "victory for the nation".

'Politicised' decision

The Tobruk parliament convened later on Thursday and rejected the ruling, saying it was handed down "at gunpoint".

"Tripoli is out of control, ruled by militias outside the state legitimacy and therefore, the ruling was issued at gunpoint", it said.

The parliament's Facebook page reported that the house of Supreme Constitutional Court judge Bashir al-Ryani, who had withdrawn from the court on Wednesday, was attacked and torched "for (his) refusing to participate".

Abu-Bakr Baeira, a leading lawmaker in Tobruk, described the ruling as "politicised'' and warned it would only further partition Libya.

"We don't recognise anything that comes out of it," Baeira told The Associated Press news agency over the phone.

The UN said it would "closely" study the ruling, and will consult "Libyan stakeholders across the political spectrum, and with international partners".

It also said that it remained "committed to working with all parties to help Libya overcome the current political and security crisis".

Rival armed rebels have formed two loosely affiliated blocs: one backing the government in Tobruk and seen as more moderate, the other backing the leaders in Tripoli and seen as more religiously conservative.

Recent violence between rival sides has claimed hundreds of lives and displaced thousands in the past few weeks.

Libya has been gripped by unrest since the 2011 uprising that toppled longtime ruler Muammar Gaddafi, as the weak central authorities have struggled to rein in regional, ideological and other armed groups who control much of the country.

Source: Al Jazeera and agencies