LOS ANGELES (AP) Dodgers pitchers had trouble throwing strikes in the seventh, and they paid for it.
Dee Gordon had four hits against his former team, Giancarlo Stanton had a decisive two-run single in the seventh and the maligned Miami Marlins' bullpen finished off a 5-4 win over the Dodgers on Wednesday night.
The Marlins avoided a three-game sweep with the win and snapped the Dodgers' five-game winning streak.
''When you don't get ahead of guys it puts you in a spot where you have to come back over the plate to try and get a strike,'' catcher Yasmani Grandal said. ''That inning whenever we were trying to come back it would be a pitch right down the pipe and they hit it.''
The Marlins (16-19) rallied from a two-run deficit by stringing together five consecutive singles in the seventh, capped by Stanton's hit that made it 5-4.
Gordon, who was traded from the Dodgers to the Marlins in December, had two doubles and scored twice for his first hits and runs against the team that drafted him in the fourth round in 2008.
Relievers Sam Dyson, Bryan Morris, Mike Dunn and A.J. Ramos combined for 3 2-3 shutout innings after starter Jarred Cosart departed with a tight right hamstring. Ramos pitched a perfect ninth for his first career save since Steve Cishek lost his closer job.
''I'm approaching it the exact same way I'm approaching every game and so is everybody else,'' Ramos said. ''Everybody is getting ready to throw whenever. I'm throwing whenever they need me.''
The unit, which entered with a 4.71 ERA, allowed only one hit the rest of the way as the Marlins finished their 10-game road trip on a high note.
Enrique Hernandez and Joc Pederson each homered for the Dodgers (22-11).
''We should have kept on scoring a little more,'' Grandal said. ''We just missed opportunities.''
Cosart gave up five hits and four runs in 5 1-3 innings before having to leave the game after pulling up lame after Alex Guerrero's single, but the Marlins bullpen was there to pick up the slack.
''There wasn't a whole lot different, we just executed pitches and our defense made plays,'' Morris said. ''Unfortunately we can't go back and change the games we had a chance to win but getting this win is good.''
The Dodgers trailed 2-1 in the fifth before a two-run homer by Hernandez and a solo homer by Pederson put the up 4-2, but the Marlins fought back.
After the first three batters in the seventh singled to load the bases, Martin Prado laced an RBI single up the middle to bring the Marlins' within one. Stanton followed with the hit that put them in front for good.
''We were able to keep the line moving,'' Marlins manager Mike Redmond. ''It was pins and needles all the way but give these guys credit, they keep battling.''
Dodgers manager Don Mattingly was ejected in the fourth inning by third base umpire Bob Davidson after disputing a call confirmed by replay. Howie Kendrick's sinking liner was ruled caught by right fielder Stanton, and Mattingly challenged the call. The replay confirmed the call. Mattingly emerged from the dugout and argued forcefully that the ball hit the ground before Stanton caught it and umpires should have overturned their initial ruling after seeing the replay. He was quickly tossed by Davidson.
It was Mattingly's second ejection of the season and the 17th of his managerial career.
Marlins: SP Henderson Alvarez (right shoulder and elbow inflammation) will make one rehab start with Triple-A New Orleans before coming off the disabled list, Redmond said. Alvarez pitched six scoreless innings for Class-A Jupiter on Tuesday in his first outing since going on the DL April 13.
Dodgers: OF Yasiel Puig will be out ''a few weeks'' after aggravating his strained hamstring in a rehab game last week, Mattingly said. There is no timetable for his return. ... Closer Kenley Jansen (foot surgery) made the last of six one-inning rehab appearances with Class-A Rancho Cucamonga on Wednesday night and is scheduled to be activated from the DL on Saturday.
Marlins: David Phelps (2-0, 2.90) looks to continue his surge since moving from the bullpen to the rotation when the Marlins return home and open a three-game series against Atlanta on Friday. Phelps is 1-0 with a 1.80 ERA in five starts since he entered the rotation.
Dodgers: Brett Anderson (2-1, 3.52) takes the mound to open a four-game home series against Colorado. The veteran left-hander didn't allow an earned run in five innings to beat the Rockies his last start. He pitched for Colorado in 2014.