ON A day when power peacefully changed hands in Washington, democracy also registered a small but significant triumph in Africa. Backed by the United Nations and the African Union, a 7,000-member force from five African countries entered Gambia to enforce the result of the election that defeated its longtime strongman. Yahya Jammeh, who had dominated the country since 1994, supposed that he could ignore the clear results of a Dec. 1 vote and that other African leaders would be willing to tolerate his coup. Thankfully, they were not.

After trying and failing to persuade Mr. Jammeh to give up his office, the leaders of the Economic Community of West African States (ECOWAS) gave him a Friday deadline for stepping down. The winner of the presidential election, Adama Barrow, swore the oath of office at the Gambian Embassy in Senegal, which surrounds Gambia’s riverine territory and which led the intervention. When Mr. Jammeh remained intransigent, the ECOWAS force moved across the border; by late Friday the strongman appeared to be negotiating his departure with the presidents of Guinea and Mauritania.

Gambia is a tiny country, but the significance of the intervention was huge. It showed that African countries are ready to act forcefully in support of democracy at a time when leaders around the continent are seeking to entrench themselves and support for liberal values is waning in the West. President Trump vowed in his inaugural address that the United States would foreswear foreign interventions in support of its values. Fortunately for Africa, ECOWAS and the African Union, which backed the military operation, understood that sometimes such action is vital to preserving stability as well as human rights.

The bold multilateral decision was helped by Mr. Jammeh’s deep unpopularity. His rule was a model of corruption and repression: When he was not imprisoning opponents or persecuting gay people, who he said should be beheaded, he was promoting bizarre initiatives, such as an herbal cure for AIDS. Still, the willingness of African nations to act against him should send a message to rulers such as Congo’s Joseph Kabila, who resisted leaving office or holding an election after his term ended in December.

Both rulers appear to have been motivated in part by fear of prosecution for their crimes. Mr. Jammeh, who first accepted the election results, reversed himself following proposals that he be tried for human rights violations. Mr. Kabila worries about investigations into the massive wealth he has accumulated. The negotiations with Mr. Jammeh reportedly focused on providing him with a place of exile, perhaps in Mauritania, where he could avoid Gambian or international courts. Such a deal would not please some human rights advocates or his Gambian victims. But if it allows a peaceful transition by Gambia to a democratically elected government, it is a bargain worth making.