Justin Ruggiano #1 of the New York Mets hits a grand slam home run against the San Francisco Giants (Jason O. Watson/Getty Images)

SAN FRANCISCO — Madison Bumgarner hit a go-ahead two-run homer off Jacob deGrom in the fourth inning — moments after giving up a grand slam — and the San Francisco Giants came back from four runs down to beat the New York Mets 10-7 on Thursday night.

Bumgarner, who narrowly missed a home run in his first at-bat, hit a 2-2 pitch into the stands in left field to cap a five-run inning when the Giants batted around. It was Bumgarner's third home run this season and the 14th of his career.

That helped overcome a shaky outing by San Francisco's four-time All-Star. Bumgarner (12-7) allowed four runs over five innings and struck out six.

New York had taken a 4-0 lead in the fourth on Justin Ruggiano's second career grand slam in his first game back off the disabled list.

Sign up for the NJ1015.com Newsletter

Get the best of NJ1015.com delivered to your inbox every day.

(Copyright 2016 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed)