But in the top of the seventh, Anthony Recker mashed his fourth home run of the season, a three-run shot that put the Mets up for good as they won, 5-3, and clinched the four-game series.
"I just got the good part of the bat on that pitch. It just feels good to come up with a big hit like that to help us win," Recker said of his blast, which measured 424 feet. He was 0-for-19 before the homer.
The homer also brought a smile to Niese's face. He got the win, his first since June 28, with seven innings of two-run ball. He gave up five hits and three walks and fanned six.
"This year has been really weird," said Niese, who improved to 6-8 with the victory. "It seems like I'm losing with my good stuff and winning with my bad stuff.
"I'll take a win like this anytime with what I've been through this year, spending time on the disabled list and all."
"He battled, and really only made the one mistake to Ruf," Mets manager Terry Collins said.
Niese was also helped in the bottom of the seventh by center fielder Juan Lagares, who threw out the Phillies' Domonic Brown at home plate. Brown tried to score from second on Ben Revere's single to center, but Lagares charged the ball and threw to backup catcher Recker in plenty of time to put the tag on Brown.
"It was a judgment call," said Phillies manager Ryan Sandberg of sending Brown. The victory was the Mets' eighth in 10 visits to Citizens Bank Park this season, and 13th in their last 16.
New York had to hold its breath in the ninth, as Chase Utley appeared to homer over the right-field wall off Jeurys Familia, scoring Cody Asche ahead of him with two out.
However, upon replay review, the hit was ruled a ground-rule double because of fan interference, so Asche tallied, and Familia got Revere to fly out to end the game.
The turning point for the Mets was a walk to Lagares in the seventh. Matt den Dekker then doubled him home to tie the game at 2, sending Phillies starter David Buchanan to the showers. Wilmer Flores then singled off Justin De Fratus, before Recker slammed a hanging curve well over the left-field fence.
"It's never good to walk the guy leading off an inning," said Buchanan. "As far as our bullpen, it's been lights-out."
Familia earned his third save, pitching the final 1 1/3 innings. He gives the Mets another arm capable of closing if Jenrry Mejia, who is battling both a right calf injury and hernia, is unavailable.
The Mets took a 1-0 lead in the top of the fourth on a double by Daniel Murphy and single by David Wright.
But Ruf put the Phils ahead, 2-1, in the bottom of the frame with his second blast of the year that landed in the center-field bushes.