Two days after being acquired from Miami in a trade meant to boost the Dodgers' offense and playoff hopes, the slugging infielder went hitless in his first four at-bats against the Giants before homering to left-center on an 0-1 pitch from reliever Sergio Romo (3-2).
Andre Ethier, who walked ahead of Ramirez's home run, had two hits and scored twice to help pull Los Angeles within two games of first-place San Francisco. James Loney and Juan Rivera also had two hits apiece for the Dodgers.
The Giants, looking to bolster their light-hitting offense, obtained veteran infielder Marco Scutaro from Colorado in a deal that was announced during the game.
Ramirez's 15th home run of the season extended a stellar start to his Los Angeles career. He had three hits in the first two games with his new club and is batting .364 since the trade from the Marlins.
The Dodgers slugger also made a potential run-saving play in the field when he dove into foul territory to catch a throw from rookie pitcher Stephen Fife for a forceout following Matt Cain's attempted sacrifice bunt in the fourth.
Ramirez had to wait a little bit before celebrating his big blow against the Giants, however.
Kenley Jansen gave up back-to-back singles to Melky Cabrera and Buster Posey to open the bottom of the 10th. Jansen struck out the next two batters and then got Joaquin Arias to fly out for his 20th save.
Shawn Tolleson (1-0) pitched one inning for his first win in the majors.
Los Angeles needed this one after getting shut out in three consecutive games here earlier this season.
The Dodgers got a stellar outing from rookie starter Stephen Fife and just enough from the bullpen until Ramirez's heroics in the 10th.
Fife was called up from the minors before the game to make his second career start and pitched into the seventh inning. Fife also helped end the Dodgers' 38-inning scoreless streak at AT&T Park when he doubled off Cain in the fifth for his first major league hit.
Jerry Hairston Jr. followed with an RBI double and scored on Mark Ellis' single to give Los Angeles a 2-1 lead.
Before that the Dodgers had not scored at the Giants' waterfront ballpark since Sept. 11, 2011, including a series sweep earlier this season.
Los Angeles got to Cain again in the sixth when Ethier hit a leadoff double and scored on Loney's single.
Cain allowed three runs and nine hits over seven innings. The All-Star right-hander, who struck out two and didn't walk anyone, has only one win over his last six starts and was on the hook for the loss until San Francisco scored twice in the eighth.
Cabrera singled and went to third on Angel Pagan's one-out double. Brandon Belt followed with his third hit, a looping single to center that drove in two and tied the game at 3.
The Giants' biggest problem isn't their pitching, however. That's why they made the deal for Scutaro. He was hitting .271 with four home runs and 30 RBIs in 95 games for the Rockies.
NOTES: SS Luis Cruz has a 10-game hitting streak for Los Angeles. ... Giants 3B Pablo Sandoval is making progress and could return to the lineup as early as this weekend, according to manager Bruce Bochy. ... Dodgers LHP Ted Lilly threw a bullpen session and will pitch for Class-A Rancho Cucamonga on Sunday before the team decides what to do next with the 36-year-old pitcher. ... San Francisco backup catcher Hector Sanchez (left knee sprain) played seven innings for Triple-A Fresno and might see time at first base before getting activated from the DL. ... The Dodgers placed LHP Scott Elbert (elbow inflammation) on the 15-day DL. The move, which was made to open a roster spot for Fife, is retroactive to July 26. ... A fan ran onto the field and made it to home plate before being taken away by security in the middle of the fifth inning. ... Dodgers RHP Chad Billingsley (5-9) faces LHP Barry Zito (8-6) in Saturday's game, which was originally scheduled as a night game before being changed to 1:05 p.m. for television.
Hanley's First Dodger Homer a Game-winner
LA Dodgers Insider Top Stories
Dodgers' Tulsa Prospects: PitchersBarry Lewis of the Tulsa World News Company Reviews Three Key AA Tulsa Pitching Prospects.
LA Dodgers InsiderYesterday at 3:14 PM
McCarthy VS. Anderson to CLINCH NL WestMcCarthy VS. Anderson to CLINCH NL West
LA Dodgers InsiderYesterday at 10:42 AM
Kazmirs return for DodgersKazmirs return for Dodgers could be good outing
LA Dodgers InsiderFriday at 9:09 AM