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 Lord Prestongrange, the Lord Advocate, 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 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. He also receives some education in the manners and morals of polite society from Barbara Grant, the daughter of Prestongrange.
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, though with David sending 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.
It’s this way about a man and a woman, ye see, Davie: The weemenfolk have got no kind of reason to them. Either they like the man, and then a’ goes fine; or else they just detest him, and ye may spare your breath - ye can do naething. There’s just the two sets of them - them that would sell their coats for ye, and them that never look the road ye’re on. That’s a’ that there is to women; and you seem to be such a gomeral that ye cannae tell the tane frae the tither.
Prodded thus, and at an invitation from James More, David and Alan journey to Dunkirk to visit with James and Catriona. They all meet one evening at a remote inn, and discover the following day that James has betrayed Alan (falsely convicted of the Appin murder) into the hands of a British warship anchored near the shore. The British attempt to capture Alan, who flees with David and Catriona, now reconciled and shamed by James More's ignominy. The three flee to Paris where David and Catriona are married. James More dies from an illness, and David and Catriona return to Scotland to raise a family.