The Papua New Guinea parliament has elected Peter O'Neill as prime minister in an extraordinary sitting in Port Moresby.
Mr O'Neill stood unopposed and won 56 votes.
He is yet to be sworn-in after the acting governor-general delayed the planned ceremony.
The election was called after the deputy speaker Francis Marus accepted last week's Supreme Court ruling upholding an earlier judgment that Sir Michael Somare was illegally removed as the country's prime minister last August.
The speaker also disqualified Sir Michael as a member of parliament for missing three consecutive sittings this year.
Sir Michael had taken court action last year after parliament controversially declared the prime ministership vacant and chose Mr O'Neill as head of government.
The judges who ruled that Sir Michael's prime ministership was still valid have in the past week been charged with sedition.
The treasurer in Papua New Guinea's O'Neill administration says that there was no vacancy in the position of prime minister despite MPs' latest election of a new head of government.
Parliament was dissolved two weeks ago in the run-up to the June general election but has reconvened twice since then.
Don Polye, who seconded Mr O'Neill's nomination, says Mr Marus's decision to declare a vacancy was based on different legal advice to theirs.
"In other words, there is no vacancy available in the position of Prime Minister although O'Neill was in as a defacto government and the advice we got from the Attorney General and his secretary is that everything is alright and we don't need to go back to parliament to elect a new Prime Minister."
A senior member of Sir Michael Somare's political group says today's election of Peter O'Neill was fundamentally flawed.
Sir Michael's Attorney General, Sir Arnold Amet says after ruling illegally for the past ten months on the contention that the court ruling was wrong, the O'Neill group cannot now have it both ways.
Fundamentally this attempt to declare a further vacancy by reference to the fact that they recognise the Grand Chief's re-affirmation as Prime Minister, but then contend that he was nevertheless absent for three consecutive meetings (of parliament) and therefore they declare a vacancy... absolute mischief.
People in Papua New Guinea are describing the political machinations that resulted in today's election as a waste of time.
Our correspondent in PNG, Titi Gabi, says people are fed up with the situation.
Papua New Guineans are saying this is just a total waste of time, it's illegal and stuff like that and they maintain that stand. It's just a big joke now. And all we can do or all the public can do is just laugh and say get real.
Titi Gabi says it's not clear what will happen with the judges charged with sedition now the O'Neill administration has endorsed the ruling that prompted the charges.