Botswana, a tiny landlocked country north of South Africa, held an election over the weekend. The result was a victory for the incumbent, the Botswana Democratic Party, but by the narrowest margin in the country's electoral history.

It was an alarming campaign. As Amy Poteete points out at The Washington Post, the run-up to the election featured some extremely ugly politics, including the death of an opposition politician under mysterious circumstances and the alleged kidnapping and torture of others by the security apparatus. One journalist fearing for his life fled to South Africa, and his editor was charged with sedition. Nevertheless, the election itself appears to have been free of overt fraud.

To folks unfamiliar with the region, all this may seem like typical African politics. But Botswana has always been the great exception to the rule. It is the only country in the entire continent to have had free and fair elections since the end of colonial rule. But it seems even Botswana is now dealing with the same sort of postcolonial troubles that have afflicted most other African nations.

The history of Botswana's transition to democracy is like something out of a fairy tale, and well worth recounting. The story begins in 1925, when Seretse Khama, at age 4, became king of the most powerful Tswana tribe in what was then called the Bechuanaland Protectorate. In the mid-1940s, he moved to Britain to study law. There he fell in love with a white British woman named Ruth Williams, and they married in 1948.

This caused a political crisis both in Bechuanaland and in South Africa. Many tribal elites at home naturally expected him to marry another Tswana. Meanwhile, South Africa was beginning to implement grand apartheid (which, of course, included laws against interracial marriage) and objected strongly at having a neighboring state run by an interracial couple.

Khama returned home with his new wife, where they managed to convince the tribal elders and the general population that the marriage was acceptable. But the Brits were heavily dependent on South African gold and uranium, so they exiled Khama and his wife from Bechuanaland. Khama wasn't gone for long, however; after renouncing the throne, and backed by strong internal and international protests, he returned in 1956.

There he helped organize a movement for independence. In 1966, Bechuanaland became the Republic of Botswana, with Khama elected as the first president. He was even knighted by Queen Elizabeth II.

The very next year, an enormous cache of diamonds was discovered in the east of the country. Amazingly, Khama managed to sensibly invest the proceeds in infrastructure, education, and health care, while instituting strong anti-corruption measures. From 1966 to 1980, Botswana had the fastest economic growth in the entire world, and as of last year, is still ranked as the cleanest government in Africa by Transparency International, coming in ahead of Spain and Italy.

It's almost impossible to exaggerate what a mind-boggling achievement this was. Maintaining an unbroken chain of democratic elections would have been an accomplishment in itself. But if one were to select the best way to undermine an African nation's fledgling democratic institutions, a huge quantity of a single, highly valuable natural resource would rank high on the list. Even stable, industrialized nations struggle with the corruption unleashed by big resource strikes — witness creeping petrostate disease in Canada today. Tottering, freshly brutalized African nations barely had a chance. Just look at oil-devastated Nigeria. Copper-devastated Congo. Oil-devastated Angola. And diamond-devastated Sierra Leone.

But Botswana managed to thread that needle, surrounded by a viciously racist regime on three sides and a protracted civil war on the other. Many factors played a part in this success, from its small size to the fact that the Tswanas managed to preserve much of their traditional leadership. But still, Seretse Khama rivals Abraham Lincoln as a statesman, and is certainly one of the 10 finest leaders in postwar history.

However, since Khama died in 1980, things have not gone quite so swimmingly in Botswana. Though it has achieved middle-income status, with per capita GDP at roughly $15,000, Botswana has struggled economically of late. Unemployment is at roughly 20 percent (and may be much higher), and most of the population still works in subsistence agriculture. The region's HIV epidemic hit Botswana especially hard, with 23 percent of the adult population infected.

The president since 2009 has been Ian Khama, the first-born son of Seretse. He was just sworn in for a second five-year term. Like so many second-generation politicians, he's not living up to the family legacy. Here's Poteete:

Abuse of state resources has become more blatant. When pictures of the president’s campaign team traveling to a campaign event using military aircraft went viral on social media, the government responded by saying that the president has a right to military transportation for personal travel and may be accompanied by whomever he chooses. [The Washington Post]

At bottom, this is the inevitable result of a lack of democratic competition. Burnished by the enormous popularity of Seretse Khama, the BDP has won every election since independence, usually with huge majorities. Partially as a result, Botswana (like South Africa) has not yet developed strong democratic norms that make for elections fought on the policy merits, as opposed to personalities. That makes good government harder to come by.

Seretse Khama himself recognized the desirability of a loyal opposition, in an interview after his very first election victory. "I think it's healthy to have an opposition which is effective, because it keeps the government on its toes," he said. "I would have liked to have it."

Hopefully, the people of Botswana will remember those wise words.