Wainwright (14-7) missed a chance to become the first 15-game winner in the majors. He went seven innings and allowed three runs, with two coming on a fourth-inning home run by Donovan Solano -- only the sixth homer allowed by the Cardinals' ace.
"I thought for sure the ball was going foul," Solano said.
He wasn't the only one.
"That ball was 10 feet foul and it came back fair. It was just the craziest ball flight I've ever seen," Wainwright said. "He thought it was foul, the umpire thought it was foul, I thought it was foul, everyone in the park thought it was foul. And then the ball started having this ball flight back to the pole, and it ended up hitting the pole. You can't do anything about that."
It was stunner coming against Wainwright, who began the game with the best innings-to-homers ratio among all major league starters. The homer was Solano's first ever at Marlins Park in 133 games.
His only other homer this year came against another All-Star, David Price.
"You can book Donovan for every ace in the league from here on out," Marlins manager Mike Redmond said with a giggle.
Cosart allowed three hits and one walk to win for the first time since July 7. The victory came in his second start for Miami after being acquired from Houston in a trade for prospects.
"I think that's why I got traded -- they had confidence in my ability that I can help this team," Cosart said. "I have the utmost confidence in my own ability that I can come in here and help these guys win games and help make a playoff push."
He's 1-1 with the Marlins and 10-7 overall this year.
Casey McGehee led off the Marlins' fourth and hustled for a double when left fielder Matt Holliday was slow getting the ball back into the infield. Jarrod Saltalamacchia singled home the game's first run, and Solano pulled an inside sinker for his homer.
"I think I got so caught up trying to stuff it in there that I didn't juice it like I wanted to," Wainwright said. "That may be why he got to it. You've got to tip your hat sometimes. It obviously looks ridiculously stupid that I gave up a two-run homer there, but the sad thing is it probably wouldn't have mattered because their guys pitched very good and we didn't score."
Cosart, who missed his last turn because of a sore lower back, decided not to risk aggravating the injury at the plate. He took six strikes in two at-bats.
With closer Steve Cishek given the night off, Mike Dunn came on with two on and two out in the ninth and earned his first save by retiring Matt Adams. The Marlins improved to 15-10 since the All-Star break.
Marlins RF Giancarlo Stanton is aware of the buzz building that he deserves MVP consideration.
"You understand what the possibilities are," he said, "but I'm not typing MVP on Google every night."
Stanton came into the game tied for the major league lead with 31 home runs, and he led the NL in RBIs, total bases and walks. He walked twice but also grounded into two double plays.
Justin Masterson, who got only six outs in his most recent outing, starts for the Cardinals against Nathan Eovaldi in the final game of the series Wednesday. Masterson has an 11.25 ERA in two starts since joining the Cardinals, but manager Mike Matheny said he was encouraged by the way the right-hander threw in his most recent bullpen session.
22,703 (60.7% full) - % is based on regular season capacity
Home Plate - Jim Joyce, First Base - Pat Hoberg, Second Base - Doug Eddings, Third Base - Cory Blaser
Before the All-Star Break, Adam Wainwright allowed a .242 batting average in at-bats ending in his fastball, the seventh-best rate in the NL in the first half. Since then, Wainwright has allowed a .333 average in such at-bats, the ninth-worst rate in the NL. Giancarlo Stanton (.341), Christian Yelich (.338) and Casey McGehee (.328) are among the top 25 qualified hitters in baseball in such at-bats this season.