David Balfour, a lad of seventeen and newly orphaned, is directed to go and live with his rich uncle, the master of the estate of Shaws in the lowlands of Scotland near Edinburgh. His uncle, Ebenezer (as close a miser as Dickens' Ebenezer Scrooge), is shocked to suddenly have his young relative descend on him and tries to rid himself of David with an arranged accident. Failing that, he pays the captain of a brig to kidnap David and sell him into slavery in Carolina.
A collision in the fog brings onboard the brig a survivor, Alan Breck Stewart, who is carrying a dangerous amount of gold on his person. David warns him of a plan by the brig's captain and crew to overpower him and seize the money, and then finds himself fighting alongside Alan in a battle royale. By good fortune, Alan is handy with a sword and they have access to the firearms locker, and the pair so completely defeat the crew that barely enough hands remain to sail her. Limping to port, she is holed by rocks, and David finds himself a castaway.
Being in Alan's presence continues to be a chancey business. David is talking to Colin Roy Campbell, the King's Factor who has been oppressing Alan's people, when the man is shot to death, and David is chased as an accomplice. The two "take to the heather" and barely survive near brushes with redcoats as they thread through the Trossachs and other highland ranges of Scotland. Only after an arduous weeks-long trek through territory where they are actively hunted do they emerge in the more settled districts around the river Forth, only to find guards upon the bridge. With no money remaining, they must somehow cross to Queensferry, find Ebenezer's lawyer, and lay claim to David's inheritance in order to send Alan safely on to France.