Donnie Murphy hit a go-ahead two-run homer in the seventh inning, one of four Cubs home runs Wednesday in a 9-7 win over the Marlins.
Starlin Castro, Dioner Navarro and Ryan Sweeney added solo homers as Chicago avoided being swept in three games by the only team in the National League with a worse record. Navarro had three RBI and scored twice.
Six home runs were hit in the game. Adeiny Hechavarria belted a grand slam for the Marlins and Logan Morrison added a two-run homer, but Miami's three-game winning streak came to an end.
Murphy sent reliever Ryan Webb's first pitch into the left field stands for his go-ahead two-run homer in the seventh, capping a four-run rally and giving the Cubs an 8-7 lead.
"It was nice to hit home runs and, obviously, big home runs late in the game, which we haven't done much," said Cubs manager Dale Sveum.
After giving up Murphy's homer, Webb (2-6) struck out three straight to end the inning but took the loss.
The Cubs scored all four of their runs in the seventh with no outs. Navarro knocked in the first two with a single off A.J. Ramos.
Chicago is 3-3 on a nine-game homestand that ends this weekend against Milwaukee. Starter Jeff Samardzija gave up six runs and nine hits in six innings but had nine strikeouts.
Carlos Villanueva (4-8) pitched the seventh for Chicago and got the win and Kevin Gregg worked around two walks in the ninth to earn his 29th save.
The Marlins had won three in a row coming into the game on the heels of a 1-10 stretch. They haven't won four games in a row all season.
Brian Flynn, a 6-foot-7 left-hander, made his major league debut and gave up three runs on six hits and three walks in four-plus innings for Miami. He struck out two and poked a single to left field for his first career hit.
"Today was not one of our better (pitching) days," said Marlins manager Mike Redmond. "Flynn, I thought he was OK. He was a little bit wild in the zone. They got in some decent hitter's counts and got some runs off him."
A boy in the stands was hit when Marlins slugger Giancarlo Stanton let go of his bat on a swing in the sixth inning. The boy was rushed away but later returned to his seat.
Stanton singled and Hechavarria later hit a grand slam to give the Marlins a 6-3 lead.
Sweeney homered in the bottom of the sixth for the Cubs, a run the Marlins got back in the seventh when Donovan Solano tripled and scored on the catcher Navarro's errant pickoff attempt to make it 7-4.
Earlier, Morrison hit a two-run homer for the Marlins in the second and Darnell McDonald had an RBI single for the Cubs in the bottom of the inning.
Castro and Navarro hit solo homers in the third to give the Cubs a 3-2 lead.