Samoa is set to get its first female prime minister, marking the end of unprecedented political drama in the small Pacific island nation.

On Monday, the Supreme Court finally validated Fiame Naomi Mata'afa's shock April election win, ending weeks of political stalemate and calling off a re-run.

She unseated the world's second-longest serving prime minister - Tuilaepa Sailele Malielegaoi - who has been ruling the country since 1998.

Observers have described the shakeup as Samoa's democracy coming of age. 

Democratic elections are nothing new in Samoa and yet they're rarely anything that would hit global headlines.

There has basically only been one party that's ever been relevant - the Human Rights Protection Party (HRPP), which has won elections there for the past four decades.

Almost equally constant has been the man at the helm: Tuilaepa Sailele Malielegaoi - the second longest-serving prime minister in the world.

But that system began to crack last year - the first signs of which showed when several HRPP members defected to start their own opposition party, Fa'atuatua i le Atua Samoa ua Tasi (FAST).

Enter Fiame Naomi Mata'af, who quickly became a frontrunner for FAST after joining them in January.

Her political pedigree is unquestionable. 

Politically active since the mid 1980s, the 64-year old had already been Polynesia's first female deputy prime minister and will be only the second woman in the region to head a government.

"Fiame is a strong figure, someone people have always looked up to," Sapeer Mayron, of the Samoan Observer, told the BBC.

"She's seen as very principled, and as bringing a dignity to politics that many people feel has been lost."

Kerryn Baker, Pacific affairs expert at the Australian National University, says that Fiame's appointment is "an important milestone for Samoa".

"She was already very much a role model for women in Samoa, but now she's broken through yet another glass ceiling."

Ms Mata'afa comes from royal lineage and is the daughter of the country's first prime minister.

But there's much more to her political success than just inherited legacy.

"In the traditional context she has equal or higher status to the state leadership, and for sure above other chiefly titles," Ms Mayron says. In Samoa, custom and respect for her status would dictate that Ms Mata'afa be addressed by her chiefly title of Fiame.

"Her status and family legacy may have opened doors for her into the many villages and communities she visited. But she was also able to be warm and personable with them, and encouraged people to open up about their concerns or questions about those bills or social issues more broadly."

Her election campaign brought a completely new dynamic to Samoan politics.

She started by inviting people into her home for discussions and debates and soon began travelling the country to engage directly with voters in a way that was very different from how politics had been done previously.

And it worked.

When polling day came around in April, she led FAST to an unprecedented and also unexpected result.

Her party secured 25 seats, on par with the incumbent HRPP. The kingmaker would have been one single independent MP - who was about to join forces with FAST.

But then things got complicated.

Samoa has a rule that 10% of its MPs have to be women - but the five female MPs elected this time round only made up 9.8% of the 51 overall seats.

Few saw this as failing the 10% rule but then the election commission added one more female MP to the house - who happened to be a member of the incumbent HRPP.

Despite FAST crying foul over this "trickery", the result then stood at a 26-26 stalemate. Ironically, a quota supposed to increase female representation was suddenly preventing the country's first female prime minister from taking oath.

Samoa therefore found itself stuck in a unique electoral crisis, and with no precedent for the situation there was no clear way out.

Amid numerous court challenges, the election commission went on to revoke the results of the April vote and called a fresh election for 21 May.

But in a fresh twist, just five days ahead of the re-run, the country's Supreme Court ruled against both the additional female seat as well as the fresh election - and Fiame Mata'afa is finally on track to make history.