Lesotho’s prime minister has made a surprise appearance in court, where his lawyer argued that his office granted him immunity from prosecution for allegedly murdering his estranged wife shortly before he took power.

Thomas Thabane sat in the public gallery of the court in Maseru, the capital of the small mountain kingdom, with his present spouse. He had been due to appear on Friday to be charged with murder, but had not appeared, saying he had to travel to neighbouring South Africa for medical treatment.

His lawyer, Qhalehang Letsika, argued on Monday that the murder charge against a sitting prime minister raised a significant constitutional issue that needed to be resolved before charges could be read against his client. The magistrate, Phethise Motanyane, agreed to refer the case to a higher court.

Lipolelo Thabane, 58, was shot several times at close range as she sat in a car near her home, two days before husband’s inauguration in 2017. She had reportedly refused a divorce and won a court battle to retain her privileges as first lady until any formal separation.

Thomas Thabane remarried two months after her death. His current wife, Maesaiah, 42, was charged with murder this month after briefly fleeing the country. Both deny any wrongdoing and sat impassively through the hearing.

Facebook Twitter Pinterest Lipolelo Thabane, who was shot dead in 2017. Photograph: China TV

His spokesman, Thabo Thakalekoala, said: “The prime minister is protected by the constitution although he is not above the law. This whole exercise is just meant to embarrass him and nothing else.”

The case has plunged Lesotho into a political crisis. Thabane has said he will resign at the end of July, and several members of his All Basotho Convention (ABC) party have been pressuring him to go sooner to avert a political crisis. Lesotho has a history of coups and political instability.

A party spokesperson said chairman Samuel Rapapa was ready to take over, following discussions among the National Executive Council on Monday.

In theory, since the ABC has a majority in parliament, the decision does not need to put the nomination to a vote. However analysts believe that rivals for the top post will contest Rapapa’s appointment, possibly fracturing the party.

Lesotho is one of the least developed countries in southern Africa. A recent survey by the World Bank found some improvement over a 15-year period but said nearly half of its 3 million residents lived in poverty. Aid agencies have said more than 500,000 people face severe food shortages in the coming months after a protracted drought. In recent years Lesotho has tried to generate income through the cultivation of medical marijuana and tourism.

The case was brought back into the spotlight in January after a letter from Lesotho’s police chief emerged claiming communication records showed that someone at the murder scene had called Thabane’s mobile phone on the day of the crime. The killing was initially blamed on unknown criminals. Lesotho has one of the highest murder rates in the world. Investigators have since said they believe professional hitmen, possibly hired in South Africa, carried out the attack.

Facebook Twitter Pinterest Maesaiah Thabane, the prime minister’s wife. Photograph: Sumaya Hisham/Reuters

Maesaiah has been a controversial figure. Since the wedding she has been accused of interfering in political appointments. A fund she set up to help reduce poverty has been the focus of allegations of fraud and money laundering. She denies any wrongdoing.

The affair has been followed closely in South Africa, which surrounds Lesotho and has intervened before to maintain stability. Last month South Africa’s finance minister, Tito Mboweni, suggested Lesotho could become part of his country under a federal arrangement.

“While Thabane’s departure promises progress in reforming the political quagmire of Lesotho politics and security issues, it also holds danger,” said Gary van Staden, a political analyst at NKC Research, a South Africa-based economics forecasting company.

In 2014, Thabane fled Lesotho for South Africa after the army surrounded his residence and police stations in Maseru. He returned under South African police escort.

In 1998 at least 58 locals and eight South African soldiers died during a political stand-off and subsequent fighting.