The central character and narrator is 17-year-old David Balfour. (Balfour is Stevenson's mother's maiden name.) His parents have recently died, and he is out to make his way in the world. He is given a letter by the minister of Essendean, Mr. Campbell, to be delivered to the House of Shaws in Cramond, where David's uncle, Ebenezer Balfour, lives.
David arrives at the ominous House of Shaws and is confronted by his paranoid Uncle Ebenezer, who is armed with a blunderbuss. His uncle is also miserly, living on "parritch" and small ale, and the House of Shaws itself is partially unfinished and somewhat ruinous. David is allowed to stay and soon discovers evidence that his father may have been older than his uncle, thus making David the rightful heir to the estate. Ebenezer asks David to get a chest from the top of a tower in the house but refuses to provide a lamp or candle. David is forced to scale the stairs in the dark and realises that not only is the tower unfinished in some places, but the steps simply end abruptly and fall into an abyss. David concludes that his uncle intended for him to have an "accident" so as not to have to give over his nephew's inheritance.
David confronts his uncle, who promises to tell David the whole story of his father the next morning. A ship's cabin boy, Ransome, arrives the next day and tells Ebenezer that Captain Hoseason of the brig Covenant needs to meet him to discuss business. Ebenezer takes David to a pier on the Firth of Forth, where Hoseason awaits, and David makes the mistake of leaving his uncle alone with the captain while he visits the shore with Ransome. Hoseason later offers to take them on board the brig briefly, and David complies, only to see his uncle returning to shore alone in a skiff. David is then immediately struck senseless.
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.