Alberto Cabrera (1-1) struck out two in a perfect 11th to earn his first career victory.
The Cardinals entered Friday with a 2 game lead over the Milwaukee Brewers for the second wild card spot.
Carpenter threw five effective innings and was in line for the win until Barney launched a 1-2 pitch off of reliever Fernando Salas into the left field bleachers.
The Cardinals' regular closer, Jason Motte, had pitched three days in a row and four out of the last five.
Carpenter threw 77 pitches in his debut, with a light rain falling throughout the game. The 37-year-old allowed two runs on five hits. He struck out two and walked one.
Carpenter went 4-0 in the 2011 postseason, but hadn't pitched since winning Game 7 of the World Series against the Texas Rangers. He had surgery July 19 to relieve a nerve ailment that caused numbness up and down the right side of his body.
Adding his experienced arm to the rotation boosts the Cardinals' playoff push. The Brewers open a weekend series Friday night against the Washington Nationals, who clinched a playoff berth Thursday.
Carpenter held the Cubs scoreless through the first two innings, allowing three baserunners, but the aggressive Chicago bats jumped on him in a two-run third inning.
DeJesus led off the third with a triple and Barney followed with an RBI-single. Two batters later, Alfonso Soriano doubled to the left field corner to tie the game at 2-2.
Carpenter retired eight of the last nine batters he faced after Soriano's double.
St. Louis regained the lead in the fourth on a botched suicide squeeze play. Kozma led off with a triple, and was credited with stealing home when catcher Welington Castillo was unable to handle a high-and-tight pitch that Daniel Descalso offered at but could not lay down.
It was the Cardinals' first straight steal of home since Kerry Robinson in 2002.
Descalso tacked on an insurance run with an eighth inning double to chase home Matt Carpenter.
Cubs starter Chris Volstad allowed three runs in five innings of work. He gave up six hits and walked three.
NOTES: Soriano matched a career-high with 104 RBIs, set in 2005 with Texas. ... The Cardinals outrighted RHP John Gaub to make room on the 40-man roster for Carpenter, who was activated from the 60-day disabled list prior to the game. ... St. Louis sends Adam Wainwright (13-13, 3.97 ERA) to the mound against Chicago's Travis Wood (6-12, 4.25) in a Saturday matinee.
Link to boxscore: Chicago 5, St. Louis 4 (11 innings)