The former mayor of former Dakar, Khalifa Sall, was hailed by jubilant supporters as he crossed the Senegalese capital in a convoy during the night following his release from prison.
President Macky Sall pardoned his former political rival, who had been sentenced for fraudulent use of public funds, the presidency announced Sunday.
The move surprised many Senegalese, although it comes amid a de-escalation of political tensions orchestrated by Muslim leaders.
Khalifa Sall, no relation to the president, has been in jail since March 2017 and was sentenced to five years in prison in August 2018.
He was therefore barred from taking part in the presidential election in February.
As the news of the pardon spread, hundreds of his supporters gathered late Sunday outside the Rebeuss prison in Dakar, from where he emerged a few hours later.
They then accompanied his convoy across several neighbourhoods of the capital, including Grand Yoff, the electoral stronghold of the 63-year-old socialist, AFP journalists said.
Police fired tear gas to disperse the crowd, witnesses and local media said.
The former mayor at times emerged from of his car, raising his arms in a sign of victory.
After a brief stop in front of the new Grand Mosque in Dakar, inaugurated Friday, the convoy arrived in the middle of the night in the district of Parcelles Assainies, where his mother lives, according to the Senegalese media.
Khalifa Sall, 63, served as Dakar mayor from 2009 till 2018 when the president removed him from office.
A presidential decree made public Sunday said Macky Sall has "totally annulled his sentences". Two of his co-accused were also pardoned.
"I thank the head of state (Macky Sall) who had promised me this release," said Sowam Wardini, who took over as Dakar mayor from Khalifa Sall.
"Khalifa Sall is returning to his family today".
Lawmaker Ousmane Sonko, who came third in the presidential election, expressed his "immense joy".
"I salute his dignity and wish him a full recovery of his civil rights," he said.
Khalifa Sall was elected to parliament in 2017 but never got the chance to take his seat.
A popular politician, he has always believed that the case brought against him was a political move to prevent him from standing in this year's presidential election against Macky Sall, who has been in power since 2012. That claim is denied by officials.
Even though he is pardoned, Khalifa Sall's conviction is not erased, which in principle does not allow him to recover his civil rights, including the right to stand for election.
Several religious leaders have recently called for more discussion and less conflict in the country's political life.
Former minister Karim Wade, son of Macky Sall's predecessor as president Abdoulaye Wade, was also prevented from standing for the presidency because of a fraud case.
He was jailed for six years in 2015 after having been detained for two years, and handed a fine of more than 210 million euros ($230 million).
After a three-year stint in prison, he was granted a presidential pardon in June 2016.
However the constitutional court rejected his presidential election candidacy due to that conviction.