Kenya's President Uhuru Kenyatta. (Simon Maina/Agence France-Presse via Getty Images)

KENYA HAS been exhibiting some conspicuous signs of dynamism in recent days. Last week it inaugurated a $3.2 billion, 290-mile railroad between Nairobi and the port city of Mombasa, the biggest infrastructure project in the country’s 53 years of independence. That followed the groundbreaking on a $220 million complex in the capital that will include what is billed as Africa’s tallest building. Construction is booming elsewhere as the economy continues to grow at a healthy pace of about 6 percent. While Kenyans complain about crime and the cost of living, the country is thriving compared with most of its East African neighbors.

Unfortunately, that progress is threatened by a specter that has haunted Kenya for the past decade: political violence. An election campaign that got underway recently pits incumbent President Uhuru Kenyatta against Raila Odinga in an Aug. 8 vote, with each candidate backed by tribal alliances. Mr. Odinga has run three previous times and claims, plausibly, that his losses in 2007 and 2013 were due to fraud. The 2007 vote triggered a wave of violence in Nairobi and across the Rift Valley in which more than 1,300 people were killed ; a similar tragedy in 2013 was narrowly averted.

This year the warning signs of a violent outcome are abundant. Seven people have already died in incidents linked to primary campaigns. Kenya’s National Security Council reports that more than half a million illegal arms are in circulation around the country, and that politicians are forming militias to protect themselves or intimidate others. In Mombasa, police death squads have allegedly been assassinating suspected Muslim militants even as a local governor allied with Mr. Odinga campaigns to hold his own seat. Human Rights Watch released a report on Kenya last week and charged that numerous journalists “have faced intimidation, beatings, and job loss.”

Mr. Kenyatta and his vice president, William Ruto, are all too familiar with the mechanics of thuggery and incitement: Both were charged by the International Criminal Court with crimes against humanity for their roles in the 2007 violence. The cases were eventually dropped after a concerted campaign of obstruction by their government. Kenya did adopt reforms, including a new constitution that decentralized power and an independent electoral commission and Supreme Court — which in 2013 rejected Mr. Odinga’s appeals of his last electoral loss.

Whether bloodshed can be avoided this year will depend on whether the loser of what polls show as a neck-and-neck race will be ready to concede defeat. That in turn will require a quick and transparent vote count by the electoral authorities. Kenya’s international donors should press the government to hold a fair vote and opposition parties to abide by the result. All sides know from painful experience that Kenya has much to lose if its leaders fail to act responsibly. The sheen of progress that the country showed off recently could be quickly wiped out.