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. Travelling onward, the company is captured by three trolls. Bilbo stalls the trolls from eating them until dawn; when Gandalf exposes the trolls to sunlight, it turns 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—with the latter finding an Elven shortsword, which he gives to Bilbo.
The company meets the wizard Radagast the Brown, 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 on their quest without him.
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. Bilbo becomes separated from the dwarves and falls into a cave where he encounters Gollum, who accidentally drops a golden ring while killing a stray goblin 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. Noticing his ring is lost, Gollum suspects that Bilbo possesses it and attacks 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 curses the hobbit.
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 knocked unconscious and left defenceless on the ground. Bilbo saves Thorin from the orcs just as the company is rescued by eagles. They escape to the safety of the Carrock where Gandalf is able to revive Thorin. In the distance, the company sees the Lonely Mountain, where the sleeping Smaug is awakened by the knocking sound of a thrush.