PHOENIX -- Jose Fernandez mixed his pitches well, putting together a strong fourth start since returning from Tommy John surgery.
One pitch that got away from him nearly spoiled his night.
Fernandez struck out 11 in seven innings to lift the Miami Marlins to a 5-3 win over the Arizona Diamondbacks on Wednesday night, but was concerned after hitting David Peralta in the head with a pitch in the sixth inning.
"It's really scary; you never want to hit someone in the head," said Fernandez, who has become friends with Peralta after meeting him earlier this year. "The ball came out of my hand, I knew it was a really bad pitch. I was hoping for him to not get hit. I'm not too happy about that."
Fernandez (3-0) was sharp through the first five innings, hitting 98 mph on the radar gun while getting the Diamondbacks to repeatedly swing through pitches.
He lost control of a fastball when he struck Peralta on the right side of the head.
Peralta went down immediately and Fernandez put his glove over his head as the left fielder didn't move for nearly a minute.
Arizona's trainer and manager Chip Hale raced out to check on Peralta, who eventually sat up and walked off the field slowly. Peralta said the pitch hit him in the shoulder first and was fine after the game, but Hale wasn't too thrilled that the 0-2 pitch ended up where it did.
"Nobody should be pitching the ball by somebody's head. It is not the place to go," he said. "You just can't do that. People always say he didn't mean to do it. He probably didn't mean to do it, but nobody knows that."
Arizona bench coach Turner Ward was ejected after yelling something from the dugout after Peralta was hit and Diamondbacks reliever Dominic Leone was ejected in the seventh inning after hitting Christian Yelich with a pitch, but the Marlins didn't seem to mind that since Yelich was hit in the backside.
"The Diamondbacks handled it the right way," Marlins manager Dan Jennings said. "It's part of baseball."
There was plenty of baseball to be played after that and the Diamondbacks made it exciting.
In the eighth inning, Arizona had runners on second and third with no outs, but didn't score. Third baseman Martin Prado saved a run by throwing Paul Goldschmidt out at the plate after making a nifty grab and Bryan Morris struck out Oscar Hernandez with the bases loaded to end the inning.
The ninth was an even better escape act by the Marlins.
Closer A.J. Ramos, who blew a save on Sunday, walked Aaron Hill, then gave up singles to Ender Inciarte and pinch hitter Wellington Castillo to load the bases.
He clamped down after that, striking out Goldschmidt, A.J. Pollock and Yasmany Tomas for his 16th save.
"Not good for the manager's heart, but pretty exciting," Jennings said.
Fernandez did his part to get the Marlins there, allowing three runs on five hits to win for the fifth time in 18 career road starts. The right-hander also had his second RBI of the season, following J.T. Realmuto's run-scoring double with one of his own in Miami's three-run second inning off Robbie Ray (3-5).
"I feel pretty healthy," said Fernandez, who is 14-0 at home. "I feel, I don't want to say like I was before, but I feel I've grown as a pitcher and a person."
Ray had been sharp over his past two starts, allowing two earned runs in 12 2/3 innings.
The Marlins jumped on the left-hander early, scoring three runs in the second inning. Florida added two more in the fifth inning, on Ichiro Suzuki's triple and a run-scoring single by Martin Prado.
Ray allowed five runs -- four earned -- on five hits with four strikeouts and three walks in 4 2/3 innings.
"I was feeling great that first inning," Ray said. "That is something I need to work on, eliminating that bad inning. It got to me today."
Diamondbacks: Castillo was scratched from the starting lineup as a precaution due to left hamstring tightness and limped to first base after his ninth-inning single before being replaced by a pinch runner.
Marlins: RHP Tom Koehler is 3-5 with a 4.85 ERA in 10 road starts heading into Thursday's game against San Diego on Thursday.
Diamondbacks: RHP Zack Godley will make his major league debut against Milwaukee on Thursday. He was acquired from the Chicago Cubs for catcher Miguel Montero in an offseason trade.