Samoa will be led by a female prime minister for the first time in its history, after an appeals court ruling ended a months-long constitutional crisis in the Pacific island nation.

Ever since a tight general election in April, two people have claimed to be the rightful prime minister: Tuilaepa Sailele Malielegaoi, the long-serving head of the Human Rights Protection Party who had held the prime minister's office for more than two decades; and Fiame Naomi Mata'afa, head of the new Fa'atuatua I Le Atua Samoa ua Tasi (FAST) party, making her bid to become the first woman to lead the country.

The saga that followed involved deadlocked legislatures, landmark court rulings and a dramatic ad-hoc swearing-in ceremony held outside the locked doors of parliament in May after Malielegaoi refused to let members of the winning FAST party inside.

But on Friday, the appeals court ruled that the ceremony was legitimate, officially handing the office to Mata'afa and ending four decades of rule by Malielegaoi's HRPP party.

No legal avenues remain for Malielegaoi to stay in office and extend his 22-year run as prime minister. But whether the crisis is truly over will depend on his actions in the coming days, observers say.

Meanwhile, FAST politicians and supporters celebrated the historic transfer of power outside of the courthouse in Mulinu'u, where the country's parliament is located.

"The road we have walked has been filled with obstacles. We feel humbled, and are grateful to God that our mission has been accomplished, we have made it. Despite the obstacles in our pathway, this is our moment, let us move forward from here," said Laaulialemalietoa Polataivao Schmidt, the founder of FAST and an MP for the party, speaking to The Guardian.

The outgoing HRPP party had dominated Samoan politics for decades. After the previous elections in 2016, the party came to hold all but two seats in parliament, effectively disbanding the then-opposition party. Afterward, a group of politicians formed a new opposition party, FAST, in advance of the 2021 general election.

The election, held in early April, had ended in a tie, with both parties winning 25 seats in the 51-seat legislature, leaving a single independent member.

But Samoa's constitution requires that women hold at least 10% of legislative seats, and women only made up 9.8% after the April election. As a result, an electoral commission declared an additional candidate from HRPP, a woman, to be elected, giving HRPP a 26-25-1 majority. Afterward, the independent joined with FAST, deadlocking the legislature at 26-26.

The country's top court ruled in May that the electoral commission's decision to add an extra seat was invalid, giving FAST the majority at 26-25, and ordered the parliament to convene and swear in the winners.

But Malielegaoi had refused to step down, instead claiming to be the rightful prime minister and triggering a dramatic scene by locking Mata'afa and her supporters out of the parliament building in May, leaving them to conduct their swearing-in ceremony outside the doors.

Copyright 2021 NPR. To see more, visit https://www.npr.org.