Houston used a three-run Justin Maxwell home run to tie the score in the eighth before the Cubs rallied in the ninth.
It was an exciting finish to forgettable seasons for both teams. The Cubs ended up 61-101. The only team with a worse record was Houston at 55-107. Wednesday also marked the end of the Astros' stay in the National League. The team moves to the American League West Division in 2013.
Chicago was up 4-1 when Maxwell sent a rocket out beyond left field for his 18th home run of the year.
Anthony Recker was walked by Hector Ambriz (1-1) to open the Cubs' ninth and was replaced by Barney. After a botched sacrifice for an out, Tony Campana reached on a bunt single. Adrian Cardenas struck out but Starlin Castro kept the inning going with a walk to load the bases.
LaHair lined Ambriz's next pitch into right for the game-winner.
Carlos Marmol (3-3) pitched the ninth and collected the win.
The Astros used two walks and a Carlos Corporan single for a first-inning run. Chicago tied the score in the second when LaHair hit his 16th home run of the year.
The Cubs got a bases-loaded walk to Recker and a two-run single from Travis Wood for the 4-1 lead in the fourth.