Approaching his 111th birthday, the hobbit Bilbo Baggins begins writing down the full story of his adventure 60 years earlier for the benefit of his nephew Frodo Baggins. Long before Bilbo's involvement, the Dwarf king Thrór brings an era of prosperity for his kin under the Lonely Mountain, far to the East, until the arrival of the dragon Smaug. Destroying the nearby town of Dale, Smaug drives the Dwarves out of their mountain and takes their hoard of gold. Thrór's grandson Thorin sees King Thranduil and his Wood-elves on a nearby hillside, and is dismayed when they take their leave rather than aid his people, resulting in Thorin's everlasting hatred of Elves.
In the Shire, 50-year-old Bilbo is tricked by the wizard Gandalf the Grey into hosting a party for Thorin and his company of dwarves: Balin, Dwalin, Fíli, Kíli, Dori, Nori, Ori, Óin, Glóin, Bifur, Bofur, and Bombur. Gandalf's aim is to recruit Bilbo as the company's "burglar" to aid them in their quest to enter the Lonely Mountain . Bilbo is unwilling to accept at first but has a change of heart after the company leaves without him the next day. Traveling onward, the company is captured by three trolls, Tom, Bert & William, after their ponies are captured. Bilbo stalls the trolls from eating them until dawn. Gandalf exposes the trolls to sunlight, turning them to stone. They search the trolls' cave and find treasure and Elven blades. Thorin and Gandalf each take an Elf-made blade—Orcrist and Glamdring, respectively. Gandalf also finds an elven shortsword ("Sting"), which he gives to Bilbo.
The wizard Radagast the Brown finds Gandalf and the company, who tells them of an encounter at Dol Guldur with the Necromancer, a sorcerer who has been corrupting Greenwood with dark magic. The company is then chased by Orcs on Wargs. Radagast covers the company's escape as Gandalf leads the company through a stone passage to Rivendell. There, Lord Elrond discloses a hidden indication of a secret door on the company's map of the Lonely Mountain, which will be visible only on Durin's Day. Gandalf later approaches the White Council — consisting of Elrond, Galadriel and Saruman the White — about his involvement with the dwarves. He also presents a Morgul blade Radagast obtained from Dol Guldur as a sign that the Necromancer is linked to the Witch-king of Angmar, despite Saruman's skepticism. When Saruman presses concern to the more present matter of the dwarves and Smaug, requesting that Gandalf put an end to the quest, Gandalf secretly reveals to Galadriel he had anticipated this and had the dwarves move forward without him. Galadriel then asks Gandalf about his motives and encourages him in his quest, promising him that she will come in person to help him, if he should ever need her.
The company journeys into the Misty Mountains where they find themselves amid a colossal battle between stone giants. They take refuge in a cave and are captured by Goblins, who take them to their leader, the Great Goblin in the heart of the mountain. Bilbo becomes separated from the dwarves and falls into a cave where he encounters Gollum, who unknowingly drops a golden ring while killing a stray goblin, who attacked Bilbo from earlier, to eat. Pocketing the ring, Bilbo finds himself confronted by Gollum. They play a riddle game, wagering that Bilbo will be shown the way out if he wins or eaten by Gollum if he loses. Bilbo eventually wins by asking Gollum what he has in his pocket. Gollum demands three guesses, as he thinks the question is unfair, but he is unable to get the correct answer. Noticing his ring is lost, Gollum realizes that Bilbo possesses it and chases him. Bilbo discovers that the ring grants him invisibility, but when he has a chance to kill Gollum, Bilbo spares his life and escapes while Gollum shouts his hatred towards the hobbit Baggins.
Meanwhile, the Great Goblin reveals to the dwarves that Azog, an Orc war-chief who beheaded Thrór and lost his forearm to Thorin in battle outside the Dwarven kingdom of Moria, has placed a bounty on Thorin's head. Gandalf arrives and leads the dwarves in an escape and kills the Great Goblin. Bilbo exits the mountain and rejoins the company, keeping secret his newly obtained ring. The company is ambushed by Azog and his hunting party, and takes refuge in trees. Thorin charges at Azog, but is overpowered and left defenseless on the ground. Bilbo saves Thorin from the orcs just as the company is rescued by Giant Eagles. They escape to the safety of the Carrock where Gandalf is able to revive Thorin, who renounces his previous disdain for Bilbo after being saved by him. In the distance, the company sees the Lonely Mountain, where the sleeping Smaug is awakened by the knocking sound of a thrush.