WHEN Ian Khama steps down at the end of the month, after ten years as president, he will leave his country looking perky. Mr Khama has been lavished with praise as he makes a series of farewell sorties around the country. At a recent gathering of farmers, he was “gifted with 35 cattle, a bull, two sheep and goats, a horse, and shares worth 25,000 pula [$2,628] at Tlou Energy”, a coal-development company, according to the pro-government Daily News.

The statistics paint a pretty picture, too. In its annual report card on African governments, the Mo Ibrahim Foundation regularly ranks Botswana near the top. At independence in 1966 it was one of the world’s poorest places, with “only 7km of tarred road and a capital, Gaborone, that amounted to little more than a railway station,” wrote a historian. Now it boasts a GDP per head among the highest in Africa. This is largely because Botswana is the world’s second-biggest producer of diamonds, yet has only 2m people. Mineral wealth has ruined other countries. But Botswana has benefited from prudent economic policies, multiparty politics and fair elections.

Mr Khama, 65, a former general and the son of the country’s founding president, Sir Seretse Khama, has much to be proud of. He has been down-to-earth, businesslike and courageous, decrying Robert Mugabe, the former president of his much beefier neighbour, Zimbabwe, when most leaders in Africa winked at his horrors. He refused to kowtow to China, inviting the Dalai Lama to visit (though in the end he did not). More to the point, Mr Khama balanced the books, even as diamond prices went up and down. Above all, he says he will obey the constitution, which limits him to two five-year terms.

Yet all is not well in Botswana. Mr Khama has become authoritarian and aloof, relying for advice on too narrow a circle of friends. His governments have failed to wean the economy off diamonds, which may run out within 30 or 40 years (nobody knows for sure) and are anyway becoming costlier to dig out. His fondness for the armed forces has led him to buy an unnecessary arsenal of fighter jets, tanks and armoured vehicles. He has overseen an excessively rigid visa regime, stemming the inflow of talent. Corruption has spread on his watch and the bullying Directorate of Intelligence and Security Services (DISS), run by his confidant, Isaac Kgosi, has become far too big for its boots.

Mr Khama’s vice-president, Mokgweetsi Masisi, 54, a cerebral figure who once worked for UNICEF, the United Nations’ children’s agency, is a near lock to be endorsed by parliament as the new president. “He must step in fast to stop the rot and put the DISS back in its box,” says a prominent businessman in Gaborone. An assistant minister from the ruling Botswana Democratic Party (BDP), which has run the show without a break since independence, fears there will be trouble if corruption persists. The opposition and the country’s independent newspapers are calling for Mr Kgosi to be sacked as an early signal of good intent.

Mr Masisi has a year and a half until the next election. Last time round, in 2014, opposition parties won more votes than the BDP for the first time, but lost because they were divided. If the two main groups can unite, most likely under Duma Boko, an articulate Harvard-educated human-rights lawyer, they would have the best chance yet of displacing the BDP. “People are tired of 50 years of BDP rule,” says Mr Boko.

If the BDP loses, it is assumed that it would graciously bow out. That is one democratic legacy for which Botswanans could then thank the Khama family.