Knowing he needed to eat innings with the bullpen weary, Ely allowed one run over seven innings and, with three RBIs from James Loney and another from Casey Blake, turned over a three-run lead to what remained of the Dodgers' bullpen.
Ramon Troncoso got two outs; George Sherrill one big one by striking out Aubrey Huff to end the eighth inning; former Giants pitcher Justin Miller got two outs in the ninth despite allowing a leadoff homer to Pat Burrell; then with the tying run at the plate, Ronald Belisario recorded a one-pitch save, pinch-hitter Buster Posey's line drive flagged down by shortstop Rafael Furcal.
"I wanted to stay away from Belisario; he was the last guy," manager Joe Torre said of the right-hander, who picked up his first save in 104 Major League appearances. Although this was Belisario's third consecutive appearance and fourth in five days, he said he told Torre he could pitch an inning.
It was Ely's first win since May 22. It improved the Dodgers' record in the National League West to 20-5 and they're 4-1 against the Giants. They've picked up games on San Diego in consecutive days for the first time in six weeks.
"I've struggled in the past, but I've learned with the struggles that you get through it," said Ely. "I know for a fact that no matter what level, it's still baseball. I know I'll get through it, I have in the past."
Ely credited his ability to throw off-speed pitches for strikes. And he thoroughly enjoyed his introduction to the Dodgers-Giants rivalry in a Northern California setting.
"Those fans are ruthless," he said. "They're good though, I liked it. You've got to respect good fans. You've got to rise to the occasion. I heard a lot of derogatory things that I don't want to read in the paper. And sometimes you've got to chuckle a little bit. Good one. I like it."
Loney, with a team-high 54 RBIs, is on pace to drive in 113. He singled in Andre Ethier on the first-inning play that saw Ramirez injured. And he delivered the key hit of the game with two outs in the fifth inning, which started with singles by Furcal (who had three hits) and a hit-and-run single by Russell Martin that put runners on the corners.
With Loney up, Martin pulled off a delayed steal of second base to get in scoring position. On the seventh pitch of the at-bat, after fouling off two pitches, Loney singled to right, took second on the throw and was in position to score on Blake's single.
"It was a long at-bat and he was pitching me pretty tough," said Loney. "He was hitting the corners pretty good. I got out in front and hooked it."
The game also featured an impressive return of Matt Kemp, despite being benched for his third consecutive start. He took over for Ramirez in the first inning, went 2-for-4 and made two catches to rob Giants of extra bases.
"I thought he did fine," said Torre, who earlier said Kemp would return to the lineup Wednesday. "He played well. A couple hits won't hurt his confidence. The catches, he's capable, he won a Gold Glove. Nothing strange to him."
"It's frustrating for the guys. They're trying hard," said Giants manager Bruce Bochy. "They hit some balls hard that they made great plays on and that's the different in the ballgame, really."
Kemp seemed partly amused and partly annoyed at reporters' questions about returning to the field.
"I'm the starting center fielder. I'm supposed to play every day," he said. "I'm always available to play every day. It's not like I'm the fifth outfielder."