Aikenhead was indicted in December 1696. The indictment read:
"That ... the prisoner had repeatedly maintained, in conversation, that theology was a rhapsody of ill-invented nonsense, patched up partly of the moral doctrines of philosophers, and partly of poetical fictions and extravagant chimeras: That he ridiculed the holy scriptures, calling the Old Testament Ezra's fables, in profane allusion to Esop's Fables; That he railed on Christ, saying, he had learned magick in Egypt, which enabled him to perform those pranks which were called miracles: That he called the New Testament the history of the imposter Christ; That he said Moses was the better artist and the better politician; and he preferred Mahomet to Christ: That the Holy Scriptures were stuffed with such madness, nonsense, and contradictions, that he admired the stupidity of the world in being so long deluded by them: That he rejected the mystery of the Trinity as unworthy of refutation; and scoffed at the incarnation of Christ".
He further predicted that Christianity would be "utterly extirpated" by 1800.
The case was prosecuted by the Lord Advocate, Sir James Stewart (grandfather of the future Jacobite economist Steuart) who demanded the death penalty to set an example to others who might otherwise express such opinions in the future. Aikenhead was in fact the last person hanged for blasphemy in Britain.
Aikenhead pleaded for mercy during the hearing and attempted to recant his views but was sentenced to death by hanging. On the gallows, he stated his belief that moral laws were devised by humans rather than divine.
On the morning of 8 January 1697, Thomas wrote to his 'friends' that "it is a principle innate and co-natural to every man to have an insatiable inclination to the truth, and to seek for it as for hid treasure. . . So I proceeded until the more I thought thereon, the further I was from finding the verity I desired. . ." Aikenhead may have read this letter outside the Tolbooth, before making the long walk, under guard, to the gallows. He was said to have died Bible in hand, "with all the Marks of a true Penitent".
Aikenhead’s story has been told many times. Thomas Macaulay mistold it to illustrate the dictatorial powers of Scottish clergy. He wrote that "the preachers who were the poor boy's murderers crowded round him at the gallows, and. . . insulted heaven with prayers more blasphemous than anything he had uttered." More recently, George Rosie wrote in the newspaper The Scotsman, "The killing of Thomas Aikenhead, like the hounding of Salman Rushdie for the same ‘offence,’ was a disgrace. . . a prime example of a God-fixated state killing a man in an attempt to stop the spread of an idea."