Kanakorn Pianchana acquitted five Muslim men of murder on Friday before calling for a fairer judiciary.
He then recited a legal oath, pulled out a pistol and shot himself in the chest.
But the judge survived and was rushed to hospital where he is recovering from his injuries.
A statement believed to have been written by the judge before giving his ruling suggests that his suicide attempt could have been related to alleged interference in the case.
What happened in court?
The judge worked at the Yala court in the insurgency-hit south of Thailand.
After acquitting the five men of murder and firearms offences, he addressed the court with an impassioned speech that he broadcast live on Facebook.
"You need clear and credible evidence to punish someone. So if you're not sure, don't punish them," he said.