SAN FRANCISCO (AP) -- Giancarlo Stanton homered twice, the second coming after A.J. Ellis' tiebreaking two-run home run in the 11th inning, and the Miami Marlins held on to beat the San Francisco Giants 10-8 on Sunday to complete a sweep.
Miami blew a 7-4 lead when the Giants scored three runs off Kyle Barraclough in the eighth before Ellis and Stanton lifted the Marlins in extra innings.
J.T. Realmuto reached on shortstop Brandon Crawford's throwing error leading off the 11th. After JT Riddle flew out, Ellis hit a tiebreaking two-run home run. It was Ellis' first career pinch-hit home run.
Stanton, who homered in the fifth off starter Johnny Cueto, then tacked on No. 26 against George Kontos (0-3). The Marlins' All-Star slugger scored four times, walked twice and was hit by a pitch.
Christian Yelich added two doubles and scored twice, Justin Bour had two hits and two RBIs while Miguel Ozuna doubled in a run to tie a franchise record for most RBIs on road trip as the Marlins head into the All-Star break having won five of six.
Nick Wittgren (2-1) retired six batters for the win and A.J. Ramos pitched the ninth for his 17th save.
It was the Marlins' first series sweep on the road this season and their first against the Giants anywhere since 2015.
Brandon Crawford and Nick Hundley homered for San Francisco. The Giants, losers of four straight and 26 games out of first place in the NL West, enter the break with the second-worst record in baseball.
Ozuna doubled in Yelich in the third, giving him 16 RBIs on Miami's road trip. That ties the club record for most RBIs on a road trip of 10 games or longer shared by Gary Sheffield (1995) and Cody Ross (2008).
Marlins: 2B Miguel Rojas went 1 for 2 with a run scored and was hit by a pitch during a rehab outing with Class-A Jupiter. Rojas has been on the disabled list with a fractured right thumb since May 9.
Giants: LF Gorkys Hernandez was shaken up in the eighth inning when was hit in the face by the ball while trying to make a sliding catch of Dee Gordon's single. The ball landed in front of Hernandez before bouncing and hitting him.
Marlins: RHP Dan Straily (7-4, 3.31) has been tentatively penciled in to start against the Dodgers in Miami on Friday. Straily could be scratched, however, as his wife is expected to give birth soon.
Giants: Manager Bruce Bochy was unsure what the rotation will be after the All-Star break. With ace Madison Bumgarner likely back soon from the disabled list, things could get even more uncertain.