MIAMI (AP) John Ryan Murphy had a busy day at the plate.
''There wasn't a lot of runs tonight so it was nice to contribute to the ones that we did have,'' Murphy said.
Zack Godley (9-5) pitched five innings and allowed two runs and six hits for the Diamondbacks, who are 14-4 in their last 18 games.
''This team is awesome,'' Godley said. ''From the top to the bottom, it's a great team.''
Arizona's David Peralta had three hits and drove in a run, Jake Lamb had two hits and knocked in one, and Paul Goldschmidt doubled to give him 17 extra-base hits in his last 19 games.
Yoshihisa Hirano got Justin Bour to fly out with the bases loaded to end the eighth to keep the lead at 5-3.
''He's their main guy and it's at the point of the game where everybody is holding their breath and you're hoping you can execute and we did,'' Diamondbacks manager Torey Lovullo said.
Brad Boxberger pitched a perfect ninth for his 18th save in 22 chances.
''I don't think it was our cleanest ballgame, but the pitchers stepped up at the right time and we were able to overcome some mistakes and win a tough ball game,'' Lovullo said.
Starlin Castro hit his fourth home run of the season for the Marlins, who had their three-game winning streak snapped. Manager Don Mattingly served his one-game suspension for the June 19 game in which Dan Straily was ejected for intentionally throwing a pitch at Buster Posey.
''We had some opportunities and we had the right guys up,'' said Tim Wallach, who served as the Marlins' manager. ''We keep battling. That's what we say every day. These guys keep playing, trying to win a ballgame and giving us opportunities against some tough guys.''
Miami's Elieser Hernandez (0-5) struck out a career-high eight batters over four innings and allowed two runs and four hits.
''I had more strikeouts today but it wasn't my best outing,'' Hernandez said.
Ben Meyer pitched four innings in relief, allowing three runs, two earned.
Lamb and Peralta hit back-to-back doubles off Hernandez in the third for a 2-0 lead.
Bryan Holaday's groundout cut the deficit to 2-1.
Murphy doubled to left field for a 4-1 advantage in the fifth.
Castro's solo shot to left brought Miami within 4-2 in the bottom of the fifth.
Godley exited after one batter in the sixth and earned his ninth victory of the season setting a new career high. He is 4-0 with a 3.09 ERA over his last four starts.
Murphy's sacrifice fly in the seventh pushed the lead to 5-2.
The Marlins once again cut into the lead pulling within 5-3 on a throwing error by second baseman Ketel Marte in the bottom of the seventh.
LAMB HEATING UP
Lamb extending his hitting streak to six games, which includes three multihit games. He is hitting .360 (9 for 25) with one home run and three RBIs during that span.
STRAILY DROPS APPEAL
Straily dropped his appeal for his five-game suspension and began serving it Tuesday.
Diamondbacks: OF Steven Sousa (pectoral) will begin a rehab assignment as a designated hitter with Single-A Visalia on Tuesday. ... OF A.J. Pollock (thumb) took part in hitting activities. ''I heard that it went well and he felt OK,'' Lovullo said.
Marlins: C J.T. Realmuto (right wrist) missed his second consecutive game after being hit by a foul ball in Sunday's game.
Diamondbacks: LHP Robbie Ray (2-0, 4.88 ERA) is expected to be re-instated from the 10-day disabled list and make his first start since April 29 due to a strained right oblique. ''Knowing he's coming back is going to be a big boost for us,'' Lovullo said. ''Any time you bring back an All-Star or somebody of his caliber, it's a very good sign.''
Marlins: LHP Wei-Yin Chen (2-4, 6.70) is coming off a start in Colorado on June 22 in which he allowed seven runs on a season-high nine hits in four innings.
Copyright 2018 by AP. Any commercial use or distribution without the express written consent of AP is strictly prohibited.