He was called to the bar on 20 November 1661, but lost almost all his practice defending his father against a charge of embezzlement.
In exile
Stewart found it necessary to leave the country because of a pamphlet, and went to Rouen, where he became a merchant under the name of Graham. Some years afterwards he returned to Scotland, but he was suspected of having had a hand in a further political pamphlet, An Account of Scotlands Grievances by reason of the Duke of Lauderdale's Ministry, an order was issued for his apprehension. He escaped, and in England under the name of Lawson. In 1678, Stewart opened a small office in London, where he gave legal advice at half fees, his clerk meeting the clients and transmitting their statements to the invisible Stewart. Returning to Scotland in 1679, he again got into trouble in 1681, when among the papers of Archibald Campbell, 9th Earl of Argyll a memorandum in his hand was found, reflecting on the government. He took refuge in The Hague. He was present at the meeting at Amsterdam in 1685, when the expedition of Argyll was resolved on. Stewart having prepared Argyll's declaration of war, he was accused of treasonably consulting and contriving Argyll's rebellion, He was found guilty in his absence. His sentence was to be executed whenever he could be found.
Later life
Stewart was pardoned by James II of Great Britain in 1687, and returned to London. His actions have been interpreted as those of a double agent. On account of his supposed influence with the presbyterian party, he was received into favour, and employed to conduct crown cases along with George Mackenzie. In 1692, after the Glorious Revolution, Stewart was appointed Lord Advocate, and during his term of office introduced legal reforms in Scotland. He was elected Dean of the Faculty of Advocates until 1695. In December 1696 Stewart was the prosecutor in the last execution for blasphemy in the United Kingdom with the case of Thomas Aikenhead. Stewart demanded the death penalty to set an example to others who might otherwise express such opinions in the future. He resigned his position as Lord Advocate in 1709. He died in 1715 in his house at the foot of what is now Advocates Close, and was buried in Greyfriars Kirkyard. Stewart is the advocate who gives his name to Advocates Close.
Works
An anonymous work Naphthali, or, The Wrestlings of the Church of Scotland is now attributed to Stewart and the Covenanter minister James Stirling, with Stewart supplying the legal portion. It defended the Pentland Rising of 1666, in the context of the repression of the Presbyterians since 1660. In 1669 Stewart published a political pamphlet Jus Populi Vindicatum, or the People's Right to defend themselves, and their Covenanted Reign vindicated, as a reply to Andrew Honeyman's Survey of Naphtali.
Family
He was married to Agnes Traill, daughter of the Rev. Robert Traill. Anne was the widow of James Maxwell of Blawarthill. Among Stewart's children, of which he had only son, was: