The three armies almost start to fight each other, but then the wizard Gandalf appears. Gandalf tells them that an army of Goblins is coming to the Lonely Mountain, and because of that the humans, elves, and dwarves have to fight the Goblins together. The "Battle of Five Armies" is long and hard, but is finally won with the help of the Great Eagles and Beorn. Thorin's nephews Fíli and Kíli are killed in the battle. Thorin is wounded and dies afterwards. Dáin becomes "King under the Mountain". Everyone gets a part of the dwarves' treasure. In the end Bilbo returns home, and lives happily everafter.