An Istanbul court has convicted a popular comedian of insulting President Recep Tayyip Erdoğan – and handed down a sentence of almost 19 months – but ordered his release due to time served.
It has also placed him under a travel ban, preventing him from travelling outside Turkey.
A final decision in the case will come from the court of appeals.
Deniz Göktaş - who denied the charges - has already spent nearly 90 days in prison. Prosecutors had asked for up to 12 years. His case comes amid a wave of arrests in Turkey that human rights groups say is aimed at crushing dissent.
His stand-up routine went viral on YouTube, attracting more than 15 million views.
Prosecutors had singled out a line in which the comedian called the Turkish leader "a shy dictator", but Göktaş insisted there was "no criminal element" in his comments.
"Dictator is not an insult," he said, "it is a political characterisation."
But angering the president in Turkey is not funny. Göktaş was arrested and handcuffed at Istanbul airport in July when he returned from a holiday.
During his court appearance on Monday, it was clear he did not lose his sense of humour during his 88 days in solitary confinement.
"Three months have been taken away from my life," he said on the stand. "But I quit smoking, so I'll add another three months to my life." That drew laughter and loud applause in court.
Outside, supporters like Firat Aksal – a fellow comedian – were very pleasantly surprised by the verdict.
"We hardly know what to do with our happiness," he said. "We are thrilled. To be honest we weren't hopeful of getting a fair trial. "
Göktaş was released at 21:45 local time (18:45 GMT) and greeted by well-wishers, including his parents who he was seen hugging, outside a prison facility.
Aksal said Göktaş would now rest for a few days, and see his family, and then return to the stage.
After his release, Göktaş told reporters: "I'm very happy to be reunited with my family, mother, father, and friends."
But he added: "There are thousands of other people in prisons across Turkey. Some, like me, are being held in pre-trial detention, while others have been convicted because of their views.
"So, of course, it's wonderful to be out. I've missed it very much. But there is not much difference between inside and outside. I hope the day comes when we can all regain our freedom together."
Many others remain behind bars, including journalists, human rights campaigners, student protesters, LGBTQ activists, and the elected Mayor of Istanbul, Ekrem Imamoglu. Prisons are full in Turkey these days.
Erdogan and his party in the past have denied arrests, such as that of Imamoglu, have been politically motivated, insisting that Turkey's judiciary is independent.
Additional reporting by Gunce Akpamuk