He is among the numerous presidents elected in the past decade in peaceful and democratic votes in the region, building hope that a time of bloody coups and strongmen was finally gone. But several of these new presidents have tightened their grip on power by engineering an extension of their terms, jailing opponents and intimidating and imprisoning journalists.

Khalifa Sall, then Dakar’s mayor (and no relation to the president), was arrested on charges of corruption in 2017 to the howls of opposition figures and human rights advocates. While in custody, he was elected to the National Assembly, an act that should have immunized him from prosecution. But in January, he was barred from running for president after a court found him guilty of embezzling $3.2 million in public funds. He was sentenced to five years in prison.

Another potential contender, Karim Wade, son of former president Abdoulaye Wade, was also barred from running for president after a court found him guilty of corruption. The younger Mr. Wade, who was a minister in his father’s cabinet, was sentenced to six years in prison in 2015, just two days after the Senegalese Democratic Party appointed him as its candidate. He served half of his prison term before going into exile in Qatar.

Mame Adama Gueye, former president of the Senegalese bar association, said that while a trial was necessary for any government official accused of corruption, the timing of the prosecutions reeked of political motivations. The case of Khalifa Sall was particularly “shady,” he said.

“In all my life as a lawyer, I have never seen a trial process that is so rushed and shrouded in secrecy,” he said.