Ahmed Maiteg was elected with the support of Islamist blocs
Disputed Libyan Prime Minister Ahmed Maiteg says he is stepping down to comply with a Supreme Court ruling that his election was unconstitutional.
Libya’s parliament, where the chaotic vote took place last month, also said it would respect the Monday’s ruling.
Since the vote in May, Libya has had two prime ministers as Abdullah al-Thani has not ceded power, says the BBC’s Rana Jawad says in Tripoli.
Three years after Muammar Gaddafi was ousted Libya remains engulfed by chaos.
Mr Maiteg on Monday said he would be “the first” to comply with the rulings of the judiciary.
“I have God, the people and the nation as my witness that I respect the judiciary and comply with its ruling”, he said.
His rival Mr Thani said he would step down in April following an attack on his family. However, he refused to recognise the election of Mr Maiteg because of the circumstances of the vote.
The parliamentary session was interrupted by gunmen storming the building.
Politicians are divided between various Islamist groups and liberals, while rival militias run different parts of the country, our correspondent says.
At the heart of this power struggle is a toxic mix of politics and ideology, with often opaque allegiances with various powerful armed groups, she adds.
Mr Maiteg, a 42-year-old businessman from Misrata, is not an Islamist but was elected with the support of Islamist blocs.
Elections are due on 25 June, to replace the interim General National Congress, which has been acting as a parliament.