"They came out in front of us," lawyer Cheikh Koureyssi Ba said, as an AFP journalist witnessed a motorcade exiting the prison through a large crowd.
Their release follows weeks of crisis after President Macky Sall postponed the February 25 presidential vote.
It could also dramatically alter the presidential campaign, with Sonko's powerful rhetoric striking a chord with young voters.
Sonko was at the heart of a bitter two-year stand-off with the state and has been in prison since July.
The legal case against him, along with economic and social tensions, led to deadly unrest between 2021 and 2023.
The opposition figurehead came third in the 2019 presidential election but was disqualified from running in 2024.
Sonko then endorsed Faye, who has also been in prison since April 2023, to replace him on the ballot.
Faye, who is one of the main contenders for the presidency, has been unable to address voters in person since campaigning kicked off on March 9.
The "Diomaye President" coalition on Thursday organised a rally through the northern outskirts of the capital on the sixth day of the campaign trail.
Even before Sonko's release from prison, as rumours he could be freed began to circulate on social media, crowds of Dakar residents took to the streets to celebrate.
Cars and pedestrians waving Senegalese flags gathered at the prison south of Dakar where the two opponents had been detained.
"We love Sonko", they chanted.
"It's a joy. It's incredible. They released Ousmane Sonko!", said 31-year-old Mamadou Mballo Mane.
The release comes after President Sall proposed a bill granting amnesty for acts committed in connection with political demonstrations since 2021.
It was a bid to end weeks of crisis after he postponed the vote.
It was expected Faye and Sonko could be the main potential beneficiaries, but it is unclear whether they were released under the amnesty law.
Sall is not standing for re-election this year. His last-minute decision to defer the February presidential vote sparked clashes that left four dead.
A new date was finally set for March 24 after a month of political crisis.
Bouts of unrest since 2021 have killed dozens and led to hundreds of arrests in a country often viewed as a bastion of stability in coup-hit West Africa.
Sonko has been a divisive figure in the turmoil.
While some view him as an incendiary agitator, others see him as a leader of the people.
Sonko has always maintained there was a plot to keep him out of the 2024 election, while his camp and the government have traded blame for the violence.
The opposition figure was sentenced twice in 2023 -- for defaming a minister and for corrupting a minor.
He had been jailed since the end of July on a string of other charges, including provoking insurrection, conspiracy with terrorist groups and endangering state security.
His political party has also been dissolved.
(AFP)
<p>The deployment of Kim Jong-un’s troops has added fuel to the growing fire in recent weeks. Now there are claims Vladimir Putin has put them to use.</p>