When Uganda's President Yoweri Museveni signed a harsh new anti-homosexuality law early this week, it made him a hero at home and a villain to the West and human rights groups.
In what is considered to be a political masterstroke, Museveni signed the Uganda Anti-Homosexuality Act in a televised event to spurn United States President Barack Obama's warning that the enactment of the legislation would "complicate a valued relationship" between Washington and Kampala.
Not many leaders – and least of all those from the developing world, fearing likely adverse recrimination – dare to defy the mighty US.
Libya's Muammar Gaddafi vilified the West and the United Nations as "useless" in 2010, and was killed the next year in a foreign-sponsored civil war Obama said the US had led from "the rear". And Zimbabwe's Robert Mugabe is under sanctions and is regularly in conflict with "imperial powers".
It has been safer historically to stay in the good books of the West, something Museveni learned early in his rule, benefiting from Washington's rock-solid support under the US administrations of no fewer than five presidents to date.
It is arguably less risky for an African leader to be a stooge of the West than to show open disloyalty – even though the death in exile of the ousted Mobutu Sese Seko, a former close ally of the US when he was president of mineral-rich Zaire (now the Democratic Republic of the Congo), is evidence that dissenters and puppets alike are likely to suffer similar fates.
It is in this context that Museveni's defiant address on February 24, broadcast nationally and covered by CNN, was surprising – an unexpected voice had told the West it had crossed the Rubicon.
The touchy issue of homosexuality, which is outlawed or criminalised in most African and Muslim countries, as well as by big powers such as Russia, has added a new dimension to international diplomacy.
Instead of a contest between pro- and anti-gay groups, the debate has been recalibrated as a challenge between sovereignty and renewed imperialism.
Because the former colonial powers are on one side, saying that sexual orientation is a human right and not a preference that others must adopt without question, forces opposed to gay practices are coalescing to deconstruct what Museveni calls "social imperialism". So the debate elicits nationalist feelings, rallying most citizens to the side of defiant leaders.
Cheers in the press conference room, churches, bars and schools greeted Museveni's assent to the anti-gay legislation in spite of protests by Western countries and human rights groups. Most of those who celebrated may not have, or never will, read the law, but the fact that Museveni defied a sitting US president is fulfilling enough for national pride.
A similar situation played out in Kenya last year, when
Obama's former top diplomat for Africa, Johnnie Carson, warned that "choices have consequences".
Rather than discouraging voters, the warning was interpreted as Western meddling in the internal affairs of another country and galvanised people to elect Uhuru Kenyatta and his running mate William Ruto, who are both facing trial in the International Criminal Court.
And that is where meddlesome Western involvement in Africa, even when it is well intentioned, boomerangs. The West must rethink how it engages with 21st-century Africa. The usual approach of reading the riot act or issuing ultimatums will not work any longer.
In turn, defiance of the West makes stubborn leaders popular in the eyes of citizens ironically brutalised by ruthless state machinery.
That is why the West must decide whether to use persuasion to make the case for legalising homosexuality, which will take longer to yield the results it wants, or rush headlong into a wall of resistance.
Kneejerk reactions such as cutting aid – the punishment Norway, Britain and the Netherlands have prescribed for Uganda since Museveni put pen to paper – are unhelpful and counterproductive because it penalises ordinary citizens.
Mugabe, who turned 90 last week, delights in mocking Western leaders. He draws wild cheers at public functions in Kampala because many Africans do not see the justification in punishing a leader who redistributes arable land that white people took from African owners.
Neither Senegal's Macky Sall nor Gambia's Yahya Jammeh are unpopular at home for opposing homosexuality, the former having publicly told off a visiting Obama on the subject in June last year.
In addition, aid cuts remove any leverage the West has over recipient countries, and African leaders know this. They can then use the excuse of reduced aid to dictate how scarce state resources are allocated, which enables them to exercise unrestrained patronage in ways incompatible with the democracy espoused by the West.
Worse still, the withdrawal or freezing of development assistance exposes the intolerance of the donors agitating for others to accommodate homosexuals, casting them as hypocrites, perhaps with hidden motives.
As such, the US is seen to have limited options in handling Museveni, because he knows the US needs Uganda – and has no immediate alternative, for now – to execute its security errands in the restive Great Lakes region.
The Democratic Republic of Congo has been a basket case of governance problems and insecurity, and Museveni played a key role in ending the M23 rebellion that the United Nations accused Uganda and Rwanda of supporting. Uganda's military also flushed al-Shabab militants out of Mogadishu.
And it dashed to South Sudan in December, rescuing President Salva Kiir's government and the country from certain pogrom. In the early years, Uganda's army helped Rwandan President Paul Kagame's rebels to take power and to stop the genocide taking place there.
Museveni founded the army as a rebel group, and critics accuse him of using it like his personal property.
Yet the US and other Western powers need him because they are concerned that the vast Central African region could turn into a hotbed for terrorists if it was to relapse into conflict, making security co-operation their incontrovertible foreign policy priority.
By signing the anti-homosexuality law, Museveni, who has ruled for 28 years, placated even some of his fiercest critics ahead of the 2016 presidential ballot, which he is certain to contest. Without this appeasement, he could have used his security agencies to brutalise voters, bribe them or rig the vote to win, as he's done in the past.
There is, however, a skilfully created back door through which Museveni can escape unhurt from this venomous confrontation with the West. This depends on whether a constitutional court petition challenging the constitutionality of the anti-homosexuality law, filed by former presidential legal aide and MP Fox Odoi, can succeed.
If it does, then Museveni will take the credit, pleasing the West that has fêted and fortified him over the years against a backdrop of mounting domestic dissent.
Tabu Butagira is a journalist with Uganda's Daily Monitor and the 2008 David Astor fellow
Anti-gay activist and pastor Martin Ssempa (centre) leads supporters as they celebrate the signing of
Uganda's anti-gay Bill into law. Photo: Edward Echwalu/Reuters