"A great return here to New York," Giants manager Bruce Bochy said about Pagan. "He's done such a nice job since he's come back. I think we've seen the difference he makes in our club, and he certainly showed that tonight."
The switch-hitter went 3 for 3 with two walks and scored twice for the defending World Series champions, who have won four straight and seven of nine to improve to 70-81. His tiebreaking homer in the seventh inning made a winner of Petit (4-0) in his second start since nearly pitching a perfect game.
"He's a clutch player," Bochy said. "I think we would have been in a better situation than the one we're in now if we'd had Angel."
Before the game, the Mets announced that Matt Harvey will try to rehab his injured right elbow without reconstructive surgery -- a move the All-Star ace hopes is going to keep him on the mound next season.
"We have to be optimistic, because he is optimistic," New York manager Terry Collins said. "If he's able to be successful, that would be a great find for the organization headed into next year."
Pagan homered off Sean Henn (0-1) leading off the seventh to give the Giants a 5-4 lead. It was his first home run since an inside-the-park shot that ended a 6-5 victory over Colorado on May 25.
After that, Pagan missed 82 games with an injured left hamstring that required surgery. He returned on Aug. 30.
"I wanted to come back so the team finished strong and we can feel good about ourselves," Pagan said. "I know we're not going to go to the postseason or whatever, but if we finish strong I think we can reflect for next year and get ready, use this year as a motivation to prepare. I think we have a good enough team, we can't forget that."
Pagan spent four seasons with the Mets before they traded him to San Francisco in December 2011. He helped the Giants win a championship last year and then re-signed with them for $40 million over four years.
"No hard feelings," Pagan said. "When I played here, I gave it all."
Tony Abreu added an RBI double against Gonzalez Germen in the eighth, and Pagan's triple off the wall in right-center made it 7-4. Hunter Pence singled home a run in the ninth for his 20th RBI in his last seven games.
Giants reliever Sandy Rosario issued a leadoff walk in the ninth and left with a strained right hip. Sergio Romo gave up an RBI single to Daniel Murphy before retiring Lucas Duda and pinch-hitter Andrew Brown with the bases loaded to end it after 3 hours, 55 minutes.
Mets starter Zack Wheeler threw 107 pitches over five innings against his former club. The rookie walked a career-high six -- four in the second inning. In all, seven New York pitchers combined to issue a season-high 10 walks.
Wheeler was drafted sixth overall by the Giants out of high school in 2009. Two years later, they traded him to the Mets in a deal for Carlos Beltran. The 23-year-old right-hander threw a gem in San Francisco on July 10, allowing one run and three hits over seven innings in his fifth major league start.
"He just didn't have his command," catcher Travis d'Arnaud said. "He had a great bullpen. I thought it was going to be a fun one for him. It just didn't work out that way."
Petit, once a Mets prospect, came within one strike of a perfect game Sept. 6 against Arizona but finished with a one-hit shutout.
The right-hander, who beat Wheeler when they matched up in the minors April 9, gave up four runs and seven hits in six innings.
Giants 2B Marco Scutaro went for an MRI on his ailing left pinkie and it's possible he could miss the rest of the season. For now, he is day to day. ... D'Arnaud left in the fourth with a sore right shoulder after he was hit by Pence's foul ball in the second. Anthony Recker replaced d'Arnaud, dinged up several times in the past few weeks. ... Mets 3B David Wright (strained right hamstring) is unlikely to return during the three-game series. This weekend in Philadelphia is a possibility, Collins said.
Devers homers twice, bullpen strong as Red Sox top Yanks 6-2
— Rafael Devers hit two home runs, including a go-ahead blast in the fifth inning, to help the Boston Red Sox best New York Yankees ace Gerrit Cole for the second straight time at Fenway Park in a 6-2 win Friday night.
Musgrove pitches six solid innings, Padres beat Marlins 5-2
— Joe Musgrove pitched six solid innings, Tommy Pham homered and the San Diego Padres beat the Miami Marlins 5-2 Friday night.
Eduardo Rodriguez exits early with migraine symptoms
Red Sox starter Eduardo Rodriguez is forced to leave the game in the second inning after experiencing migraine symptoms.
Devers hits pair of dingers to power Red Sox past Yankees
Rafael Devers hits his 25th and 26th homers of the season to help the Red Sox beat the Yankees.
Pham fired up after solo dinger vs. Marlins
Tommy Pham lines a solo home run in the first inning for the Padres vs. the Marlins.
Ji-Man Choi belts 3-run HR in Rays' win
Ji-Man Choi extends the Rays' lead over Cleveland with a long ball to right field.