By Sam Bush

Nick Williams, Rhys Hoskins and Andrew McCutchen homered, and the Phillies held on to beat the Miami Marlins 12-9 after nearly a nine-run lead.

“What saved us was our run-scoring ability,” manager Gabe Kapler said.

The Phils’ Jean Segura left after Trevor Richards’ 90-mph fastball hit his helmet in the second inning. Segura went straight down but got up and walked off the field on his own. Kapler said it doesn’t appear Segura has a concussion but he’ll be re-evaluated today.

Jake Arrieta (4-2) allowed five runs and nine hits in five-plus innings, benefiting from the offense breaking out of a slump. The Phillies had scored a total of 13 runs in the previous six games.

“It was a pretty clean game until the sixth and I let it get too close,” Arrieta said. “I’m frustrated I wasn’t able to put together a clean sixth.”

Richards (0-4) gave up five runs and six hits in four innings.

Miami’s Jorge Alfaro hit a two-run homer off Enyel De Los Santos in the seventh and the Marlins pulled within a run on Brian Anderson’s RBI single in the eighth off Seranthony Dominguez.

But Hoskins gave the Philsa three-run cushion in the bottom half with his eighth homer.

Hector Neris pitched out of a jam in the ninth, striking out pinch hitter Chad Wallach to strand two runners for his fourth save in four tries.

Williams lined his first homer of the season into the bullpen in the second. Williams was the odd man out in the outfield after Philadelphia signed Bryce Harper and McCutchen in free agency.

“I’m just trying to stay ready, remain positive, have good at-bats,” Williams said.

Williams has started a few games because Odubel Herrera is on the injured list.

“Nick has had to endure quite a bit and the thing I see is how mentally tough he’s been,” Kapler said.

The Phillies tacked on three more runs after Williams went deep. After Segura was hit to load the bases, Harper drove a two-run double to right to make it 4-0.

McCutchen connected in the fourth for his fifth homer and his 800th career RBI.

Maikel Franco ripped a two-run single in the fifth, Arrieta followed with an infield single that drove in another run and Sean Rodriguez hit a two-run double to cap a five-run inning off Jarlin Garcia.

Arrieta took a 10-1 lead into the sixth but exited after loading the bases. Curtis Granderson’s third hit of the game, a two-run double off Jose Alvarez, cut the deficit to 10-5.

“I liked the way the guys continued to play but you don’t get any moral victories,” Marlins manager Don Mattingly said.