The book begins precisely where Kidnapped ends, at 2 pm on 25 August 1751, outside the British Linen Company in Edinburgh, Scotland.
The first part of the book recounts the attempts of the hero, David Balfour, to gain justice for James Stewart (James of the Glens), who has been arrested and charged with complicity in the Appin Murder. David makes a statement to a lawyer and goes on to meet William Grant of Prestongrange, the Lord Advocate of Scotland, to press the case for James' innocence. However, his attempts fail, as after being reunited with Alan Breck he is once again kidnapped, and confined on the Bass Rock, an island in the Firth of Forth, until the trial is over, and James is condemned to death. David also meets and falls in love with Catriona MacGregor Drummond, the daughter of James MacGregor Drummond, known as James More (who was Rob Roy's eldest son), also held in prison, whose escape she engineers. David also receives some education in the manners and morals of polite society from Barbara Grant, Prestongrange's daughter.
In the second part, David and Catriona travel to Holland, where David studies law at the University of Leyden. David takes Catriona under his protection (she having no money) until her father finds them. James More eventually arrives and proves something of a disappointment, drinking a great deal and showing no compunction against living off David's largesse. At this time, David learns of the death of his uncle Ebenezer, and thus gains knowledge that he has come into his full, substantial inheritance. David and Catriona, fast friends at this point, begin a series of misunderstandings that eventually drive her and James More away, although David sends payment to James in return for news of Catriona's welfare. James and Catriona find their way to Dunkirk in northern France. Meanwhile, Alan Breck joins David in Leyden, and he berates David for not understanding women.