information:classification, structural:reformatting
Final years in Edinburgh, 1564–1572

On 26 March 1564, Knox stirred controversy again when he married Margaret Stewart, the daughter of an old friend, Andrew Stewart, 2nd Lord Ochiltree, a member of the Stuart family and a distant relative of the Queen, Mary Stuart. The marriage was unusual because he was a widower of fifty, while the bride was only seventeen. Very few details are known of their domestic life. They had three daughters, Martha, Margaret, and Elizabeth.

When the General Assembly convened in June 1564, an argument broke out between Knox and Maitland over the authority of the civil government. Maitland told Knox to refrain from stirring up emotions over Mary's insistence on having mass celebrated and he quoted from Martin Luther and John Calvin about obedience to earthly rulers. Knox retorted that the Bible notes that Israel was punished when it followed an unfaithful king and that the Continental reformers were refuting arguments made by the Anabaptists who rejected all forms of government. The debate revealed his waning influence on political events as the nobility continued to support Mary.

After the wedding of Mary and Henry Stuart, Lord Darnley on 29 July 1565, some of the Protestant nobles, including James Stewart, 1st Earl of Moray, rose up in a rebellion known as the " Chaseabout Raid ". Knox revealed his own objection to the marriage while preaching in the presence of the new King Consort on 19 August 1565. He made passing allusions to ungodly rulers which caused Darnley to walk out. Knox was summoned and prohibited from preaching while the court was in Edinburgh.

On 9 March 1566, Mary's secretary, David Rizzio, was murdered by conspirators loyal to Darnley. Mary escaped from Edinburgh to Dunbar and by 18 March returned with a formidable force. Knox fled to Kyle in Ayrshire, where he completed the major part of his magnum opus, History of the Reformation in Scotland. When he returned to Edinburgh, he found the Protestant nobles divided over what to do with Mary. Lord Darnley had been murdered and the Queen almost immediately married the chief suspect, the Earl of Bothwell. The indictment of murder thus upon her, she was forced to abdicate and was imprisoned in Lochleven Castle. Lord Moray had become the regent of King James VI. Other old friends of Knox, Lord Argyll and William Kirkcaldy, stood by Mary. On 29 July 1567, Knox preached James VI's coronation sermon at the church of the Holy Rude in Stirling. During this period Knox thundered against her in his sermons, even to the point of calling for her death. However, Mary's life was spared, and she escaped on 2 May 1568.

The fighting in Scotland continued as a civil war. Lord Moray was assassinated on 23 January 1570. The regent who succeeded him, the Earl of Lennox, was also a victim of violence. On 30 April 1571, the controller of Edinburgh Castle, Kirkcaldy of Grange, ordered all enemies of the Queen to leave the city. But for Knox, his former friend and fellow galley slave, he made an exception. If Knox did not leave, he could stay in Edinburgh, but only if he remained captive in the castle. Knox chose to leave, and on 5 May he left for St Andrews. He continued to preach, spoke to students, and worked on his History. At the end of July 1572, after a truce was called, he returned to Edinburgh. Although by this time exceedingly feeble and his voice faint, he continued to preach at St Giles'.

After inducting his successor, James Lawson of Aberdeen, as minister of St Giles' on 9 November, Knox returned to his home for the last time. With his friends and some of the greatest Scottish nobles around him, he asked for the Bible to be read aloud. On his last day, 24 November 1572, his young wife read from Paul's first letter to the Corinthians. A testimony to Knox was pronounced at his grave in the churchyard of St Giles' by James Douglas, 4th Earl of Morton, and newly elected regent of Scotland: "Here lies one who never feared any flesh". After the churchyard's destruction in 1633 the precise site of Knox's grave cannot be established.