On their long journey to Erebor, Thorin and his companions were captured by Wood-elves as they neared the eastern edge of Mirkwood, and imprisoned in their halls. It was Bilbo Baggins who engineered their escape, concealing them in barrels that the Elves unknowingly released into the Forest River, which then carried them down to the Long Lake. Wearing his Magic Ring, Bilbo himself clung to one of the barrels, and so made his way with the Dwarves to Lake-town.
Some weeks later, Bilbo found himself confronted by the Dragon Smaug, and needing to distract the great Dragon, he invented a series of riddling names and titles for himself, including 'Barrel-rider' from his adventures on the river. The name 'Barrel-rider' seemed harmless at the time, but it was actually the trigger for the great events that followed. Smaug immediately saw the connection between barrels and the Lake, and it caused him to attack Lake-town, an act which gave Bard the chance to destroy the Dragon. So, if Bilbo had never called himself 'Barrel-rider', Smaug might still have held the Lonely Mountain at the time of the War of the Ring.