With the Dodgers trailing 1-0, Garret Anderson drew a one-out walk from Giants' starter Barry Zito. Blake DeWitt pinch-ran for Anderson, and Dodgers Manager Joe Torre called on Ramirez to bat for pitcher Ramon Troncoso.
After Zito was lifted for Sergio Romo (0-1), Ramirez belted a 1-2 hanging curveball into the left field seats to give LA the lead.
It was Ramirez's 548th career home run, moving him into a tie with Mike Schmidt for 14th on the all-time home run list.
Troncoso (1-0) notched the victory after getting one out to end the top of the eighth and Jonathan Broxton shut the Giants down in the ninth to get his first save of the season and give Los Angeles the rubber match of the three-game series at Dodgers Stadium.
Zito pitched well, allowing only four hits in 7 1/3 innings. Los Angeles starter Clayton Kershaw gave up four hits and struck out nine over seven-plus innings.