JOHANNESBURG (AP) — Madagascar's prime minister has resigned as part of a court-ordered effort to overcome a political crisis in a country struggling with instability and poverty.

The resignation Monday of Prime Minister Olivier Mahafaly Solonandrasana opens the way for the appointment of a candidate deemed acceptable to opposition factions as the Indian Ocean nation prepares for elections this year amid concerns about violence. The defense minister has warned that the military could intervene if tensions escalate in a standoff linked to election law changes that the opposition groups said would bar their candidates from running for president.

Madagascar's highest court says some changes were unconstitutional and that President Hery Rajaonarimampianina, who appointed the prime minister, must establish a "consensus government."

International mediators have unsuccessfully sought to mediate a solution to the crisis.