The ancestral home of the King under the Mountain, it became a Dwarven stronghold, where the Dwarves became a numerous and prosperous people. The Dwarves of that time were skilled in masonry and stone work, and there was great demand for their work by the surrounding peoples. Clearly through this the Dwarves got very rich and amassed a large amount of gold and treasure. This is what attracted Smaug to the mountain.
Whilst Thorin Oakenshield was one day out hunting, Smaug came from the mountains as a young dragon, and took over the mountain, hoarding all the gold. Thráin II and several companions escaped by (as was later discovered) a secret door. For many years the dwarves lived in exile in the Blue Mountains until, by a chance meeting, Gandalf the Grey met Thorin Oakenshield, and they planned to reclaim the mountain. This is told in detail in The Quest of Erebor.
In The Hobbit, Bilbo and Thorin's company travel to the Lonely Mountain to regain the treasure Smaug had stolen. Set into the side of the mountain was a secret door, five feet high and wide enough for three to walk abreast. Gandalf had managed to obtain the door's key, which would only open it when the setting sun and the last moon of autumn were in the sky together. By a fortunate coincidence, this happened just as Bilbo and the Dwarves arrived.
By more luck than wisdom Smaug was eventually slain—shot out of the sky with a well-aimed arrow to his only weakspot by Bard the Bowman, a man of Lake-town—and Thorin claimed the mountain. Bard later became king of the area in the shadow of the Lonely Mountain, known as Dale. However Elves of Mirkwood and Men of Lake-town claimed a part of the treasure, which Thorin refused to share. This led to the Battle of Five Armies, where Dáin II Ironfoot came to the aid of his cousin Thorin, but Dwarves, Elves, and Men joined ranks together with the Eagles and Beorn against the Orcs. During the battle, Thorin was mortally injured, and the titles King under the Mountain and King of Durin's Folk passed to Dáin.
With the restoration of the Kingdom under the Mountain the area became prosperous again, and Dwarves and Men reforged their friendship.