MUSIC blasts from speakers mounted on the back of a truck in a rubbish dump in a corner of Lusaka, Zambia’s capital. Young men with bandannas over their faces form a security cordon. Children climb on top of a dumpster to get a better view. A woman swigs from a bottle of local rum as she dances provocatively on the makeshift stage. A man in a suit steps up and the music stops. “Zambia!” he shouts. “Zambia!” roars back the crowd.

This is not a music festival. It is a political rally. Yet for all the jovial colour of the occasion, democracy in Zambia is not well. The rally was held on a stinking rubbish dump because the government refused to let Hakainde Hichilema, the main opposition candidate for the presidency, use any other public space in the area. Mr Hichilema was repeatedly refused permission to fly his helicopter to campaign elsewhere. The country’s leading independent newspaper, the Post, was shut down, ostensibly over a tax bill, after it reported on what it said were plans to rig the election. Several rallies turned violent, leaving at least one person dead.

After the election, held on August 11th, the counting of the votes lasted four days instead of the usual two. On the third day, Mr Hichilema’s party withdrew from the verification process, complaining that the electoral commission was colluding with the party of the incumbent, Edgar Lungu, to boost his vote. In the end Mr Lungu was narrowly re-elected, despite a collapsing economy and an inflation rate of 20%.

Zambia’s marred election is a particular disappointment. In 1991 it was the second country on the continent to expel an incumbent ruler at the ballot box, following Benin by a few months. It again booted out the ruling party in 2011, establishing a healthy pattern of alternation that now seems threatened.

Zambia is an unnerving example of how democracy, which had seemed finally to be about to bloom on the world’s poorest continent, is still struggling to take root in many parts of it. Looked at through a wide lens of history, Africa’s standard of governance is almost unimaginably better than it was at the end of the cold war. Then a dart thrown at the map would almost certainly have landed on a one-party state, military junta or outright dictatorship.

Economic liberty was much scarcer then, too: various forms of socialism abounded, from Tanzania to Ghana, Ethiopia to Angola. Freedom House, an American think-tank, reckons that in 1988, just before the cold war ended, only 16 countries in sub-Saharan Africa could be classified as “free” or “partly free”. Since then, the organisation reckons that 29 of the 48 countries in the region can be considered “free” or “partly free”.

Yet zoom in the historical lens to view the past few years and it seems that the picture is mixed. Some places are seeing progress. In South Africa, the African National Congress, which has ruled since the end of apartheid, lost its majority in several major cities in local elections this month. Despite efforts by its president, Jacob Zuma, to hollow out institutions such as the prosecutors’ office, national broadcaster and anti-corruption agency, a critical press, independent judiciary and vocal opposition are keeping the government on its toes. In Nigeria, Africa’s most populous country, a corrupt and incompetent ruling party was voted out for the first time since the end of military rule in 1999.

Yet elsewhere democracy appears to be withering. The most recent tally of free countries has fallen from a peak of 34 a decade ago (see chart). A number of countries which, like Zambia, had been becoming more open and free, have seemed to slide backwards.

It won’t be built in a day

The most recent threats to democracy in Africa vary, even if some are familiar. They include the short-term interests of Western countries; a demand for minerals and oil; and the rising influence of new powers such as China. Underlying these are the bigger enduring problems of poverty and weak institutions.

Modern Africa’s first taste of democracy came in the form of fledgling parliaments bestowed by departing colonial powers. As Britain and France dismantled their empires, they left behind crude carbon copies of their own forms of government (though Portugal, a dictatorship until 1975, left its colonies in Mozambique and Angola mired in civil war). Indeed, Sir Abubakar Tafawa Balewa, Nigeria’s first prime minister, closed his speech at Nigeria’s independence ceremony with the words, “God Save Our Queen”.

Yet in the early days of independence most African leaders swiftly imposed their own stamp on the fragile states they had inherited, reshaping institutions they often condemned as colonial impositions. New ideas such as “African socialism” swept the region, along with the notion of a specifically African form of democracy. Leaders such as Julius Nyerere of Tanzania and Kwame Nkrumah of Ghana led the way in arguing that new states needed to put national unity ahead of multi-party democracy, often imposing one-party systems of government that swiftly turned into bullying autocracies. In many cases—witness Ghana and Nigeria—unity was supposedly saved by military coups that were easily mounted because armies were the only strong institutions inherited from empire.

Some military juntas did hand power back to civilians, but in many cases they led to dictatorship in whatever guise. An extreme example of this was Mobutu Sese Seko of Congo (or Zaire, as he renamed it), who, after taking power in a coup, became the archetype of an African dictator. Before the news was broadcast to the nation every morning on television, his face would emerge out of the clouds, framed by the sun. Mobutu declared that absolute rule was authentically African. “Can anyone tell me that he has ever known a village that has two chiefs?” he would ask anyone who questioned his authority.

Yet as superpower competition fell away after the collapse of the Soviet Union in 1991, so too did the no-strings-attached military and economic aid that had sustained many African dictators for so long. The failure of socialism and one-party states was laid bare both in Europe and Africa. In some parts of the continent—most notably Democratic Republic of Congo (DRC), which was renamed again in 1997—the result was the collapse of the state and the onset of civil war. But in many places the result was the spread of new, more open types of government. Ivory Coast had a multi-party poll in 1990; Benin and Zambia followed in 1991; then Kenya in 1992 and Tanzania in 1995. Ghana and Nigeria reverted to civilian rule with multi-party elections in 1996 and 1999 respectively. Since 1991 incumbents have been ejected peacefully at the ballot box at least 36 times. Among Arabs the figure is zero.

Such progress has continued in places such as Nigeria and Ghana, with the latter preparing for elections in December that are sure to be fiercely contested. In 2011 in Liberia, Ellen Johnson Sirleaf, the continent’s first elected female president, won re-election in a vote the Atlanta-based Carter Center called the “best run and most credible election in the country’s history”.

Yet in other places democracy seems to have eroded, thanks largely to presidents changing or flouting constitutions to cling on to power. In Uganda, Congo-Brazzaville and Burundi, Presidents Museveni, Denis Sassou Nguesso and Pierre Nkurunziza have all won flawed elections in the past year after dropping term-limits that required them to step down. In all three, opposition has been violently crushed.

Time for two-terming

Rwanda’s president, Paul Kagame, will run for a third term in 2017 after changing his country’s constitution last year. In DRC President Joseph Kabila seems set simply to ignore the constitution he helped enshrine in 2006. His final term comes to an end in December, but he has refused to hold elections, citing logistical problems.

Optimists point out that three decades ago almost no African countries had term limits; since then, some 33 of 48 new constitutions enacted in Africa have included them. Most Africans say they like the idea. Afrobarometer, a polling firm, found that about three-quarters of people in 34 African countries said that presidential mandates should be restricted to two terms.

In parts of east Africa the problem is less the domination of politics by one man and more the fact that politics is often contested along tribal lines or dominated by powerful incumbents who blur the division between party and state. In Ethiopia, for instance, an authoritarian government dominated by the Tigrayan ethnic group has whittled down the opposition, imprisoning many of its people; in last year’s election the ruling party won all the seats in parliament. In Tanzania, where a new president, John Magufuli, took office last year, his Chama cha Mapinduzi (Party of Revolution), the longest-ruling in Africa, was never likely to lose. When the people on the island of Zanzibar dared to vote for a different party, the result there was promptly annulled.

In Kenya President Uhuru Kenyatta and his allies seem determined at all costs to win next year’s elections again. If the result is close, or people believe it to have been rigged, there is a risk that the violence that led to some 1,300 deaths in 2008 will recur.

In southern Africa the picture is mixed. Democracy looks entrenched in South Africa, it functions fairly well in Namibia and Botswana, and more or less in Malawi. But in Zimbabwe and Mozambique voting has failed to push out two of the most spectacularly corrupt regimes, and Swaziland is ruled by an absolute monarch.

So why has democracy across sub-Saharan Africa’s heterogeneous 48 countries recently stumbled? In some places it was never strongly rooted in the first place. Mr Kagame, for example, has always been an autocrat at heart, even though he rode to power with an initial vote of confidence. Under Mr Kabila, despite his messy election in 2006, DRC was never going to become a proper democracy.

And even where states embrace the outward forms of democracy, holding regular elections, few enjoy the checks and balances provided by strong institutions and independent courts and civil services. This shortcoming is compounded by the fact that in many African countries the strongest institution is the army.

Yes General, er, Prime Minister

Nicholas Cheeseman, an academic at Oxford University, reckons that of 91 presidents and prime ministers to have held office on the continent in civilian regimes since 1989, 45% once either served in the armed forces or were guerrillas before becoming politicians. This includes all four presidents in the Great Lakes region around eastern Congo, as well as Nigeria’s Mr Buhari. Coups are far less common these days; the African Union, often an ineffectual organisation, has recently taken a firm stand against them. Yet the prevalence of so many former fighting men in civilian office highlights the influence that armies still wield in politics.

This may well be reinforced by a shift in the priorities of Western governments, from promoting democracy to fighting jihad. Uganda’s contribution of 6,000 soldiers to suppress al-Shabab, a jihadist group in Somalia, means that Western governments are less inclined to criticise Mr Museveni. The same applies to Ethiopia’s government, which also acts against al-Shabab. It has been accused by Human Rights Watch of killing more than 400 peaceful protesters since last November, yet Western criticism is muted at best.

African autocrats have also benefited from China’s rise as an economic and political power. The authoritarian regime of José Eduardo Dos Santos in Angola, for instance, has turned to it for cash when it has disliked the conditions such as making its budget transparent which are imposed by organisations like the IMF.

Yet neither Chinese money nor Western apathy alone explains why things are getting worse in countries such as Zambia, Tanzania and Congo. Part of the explanation lies in the narrow nature of most African economies. Many of them rely on the export of one or at best a handful of commodities. In the likes of Angola, which depends hugely on its oil, or Zambia, which relies on its copper, the easiest path to riches is not by coming up with a new product or service, but by going into politics or befriending someone who has done so; the government is funded by royalties from oil or by mining companies rather than by taxes on people who may start demanding better governance and services.

In turn, money is redistributed downwards in exchange for votes. At political rallies across the region people are paid in cash for turning up. On polling day they are bused in and given food and T-shirts.

Sir Paul Collier, an economist at Oxford University, thinks the defining feature of politics in much of the continent is that the winner takes all—and uses state power to try to keep it. Institutions such as the civil service, electoral commissions and the courts often lack independence. That creates a vicious dynamic, says Sir Paul. Instead of governing well, politicians are keener to steal money so as to bribe and rig their way back to power. Ideological differences and arguments over policy barely register in election campaigns. In many cases politicians fall back on appeals to tribal, religious or regional loyalties.

In Kenya, where five leading ethnic groups make up more than three-fifths of the population, tribal leaders generally campaign on variations of the promise that it is their group’s “turn to eat”. Politicians from two ethnic groups—the Kikuyu and the Kalenjin, a clutch of ten or so smaller tribes linked by language—have had the biggest say in running the country for most of its 52 years since independence. Politicians from another big tribe, the Luo, have tended to lead the opposition. Most Kenyan elections since the return of multi-party democracy have been marred by varying degrees of violence.

Across the African board, the winner-takes-all aspect is common almost everywhere, including South Africa, which has the most advanced economy and strongest institutions. Yet Mr Zuma, its president, was roundly criticised a few years ago for saying, “You have more rights because you’re a majority; you have less rights because you’re a minority. That’s how democracy works.” This tendency explains why elections in large parts of Africa so often result in riots and why relatively democratic countries, such as Ghana or Kenya, seem to suffer more from corruption than some more autocratic ones, such as Ethiopia or Rwanda.

Just the beginning Yet constitutional changes to devolve power can go some way to improving things. Kenya’s newish constitution has given marginal groups more of a say over their own affairs. Democracy can plainly be improved by stronger institutions and less politicised civil services, as well as by a vibrant civil society and free media. One big hope lies in the continuing rise of an educated, wealthier middle class. As Africa in general gets richer and the younger generation turns against the bribery and corruption of the old order, the demand for decent governance will get louder. According to a study by Sir Paul, democracies become less inclined to violence and patronage-based politics as incomes rise. Once GDP per head rises above roughly $2,700, greater democracy generally begins to make countries more stable. Some 12 sub-Saharan countries have reached this level. Except for the corrupt petro-states of Equatorial Guinea and Gabon, they are the ones where democracy is performing best. Urbanisation should also play a role in promoting openly contested politics. In Uganda and Tanzania national politics may still be dominated by parties long accustomed to rule, but the main cities of Kampala and Dar es Salaam are run by mayors from opposition parties. In South Africa the two cities that host Parliament and the seat of government are now run by parties opposed to Mr Zuma’s ANC. If it is true that urban voters, who on the whole are better educated and richer than their rural counterparts, tend to be more willing to kick out incumbents, then demography is on democracy’s side. By 2050 more than half of Africans will live in cities, up from just a third today.

Technology may also lend a hand. In Nigeria young voters with smartphones snapped pictures of the tally at remote counting stations and posted the pictures on social media, stymying attempts by the ruling party to rig the vote. As smartphones proliferate and more people have access to the internet, crooked governments will be less able to ignore the voters’ wishes. And as Africa becomes more urban and its middle class grows, so too will the demand—egged on by social media—for democracy. Whereas previous waves of democratisation in Africa came from abroad, expect Africans themselves to generate the next democratic tsunami.