Papua New Guinea Prime Minister Peter O'Neill said on Thursday a military mutiny in the Pacific Islands nation was over and the government had regained full control of its military barracks.

Soldiers loyal to former prime minister Michael Somare earlier in the day staged a mutiny, putting the military commander under house arrest and demanding O'Neill reinstate Somare as the leader of the resource-rich country.

The government has now taken control of the barracks and the soldiers have now withdrawn to Taurama Barracks, those who were at Murray Barracks, O'Neill told reporters in the PNG capital Port Moresby.

The commander is now released, he's not under house arrest. And as a result the government has taken full control of the defence headquarters.

We will now start an investigation into the issues that the soldiers have and we'll resolve them as we move forward.

O'Neill said the mutiny leader, retired Colonel Yaura Sasa, was being dealt with, but he did not clarify whether Sasa had been detained.

Papua New Guinea has for months been gripped in a political deadlock. O'Neill took office in August after Somare was ruled ineligible as a member of parliament due to illness and absence from the legislature.

In the early hours of Thursday, up to 20 soldiers raided the main army barracks, seized their chief commander and placed him under house arrest in an action dubbed Operation Protect the Constitution.

I call on the disciplinary forces to ensure public safety by exercising restraint at all times, Somare said in a statement announcing he had appointed a new defence force chief and again declaring he was the legitimate prime minister.

Residents of Port Moresby said the dusty port capital was quiet although tense with roadblocks around the main army barracks.

PNG has a history of political and military unrest. An army mutiny in 1997 overthrew the government after it employed mercenaries to try to end a long-running secessionist rebellion on the island of Bougainville, home to a big copper mine.

The Supreme Court in December ordered Somare reinsated but O'Neill rejected the ruling, with parliament again voting him prime minister, leaving two competing leaders.

(Additional reporting by Mark Bendeich, Lincoln Feast, James Grubel and Chris McCall; Editing by Robert Birsel)