Tim Lincecum's right knee still throbbing, Chase Utley hustled out toward the mound to apologize that his bat had struck the pitcher.

A tense four-game series featuring a benches-clearing brawl between NL division leaders ended with an act of sportsmanship.

"He said, 'Sorry, man,'" said Lincecum, San Francisco's ace. "Bad hop. Bad luck."

Lincecum stayed sharp until Utley accidentally lost his grip and the Giants ended the Philadelphia Phillies' season-high nine-game winning streak, tagging Roy Oswalt in a 3-1 win Sunday.

Jeff Keppinger had four hits as the Giants spoiled Oswalt's return from the disabled list and avoided a four-game sweep.

"That was one of the biggest games of the year, really," Giants first baseman Aubrey Huff said. "Four-game sweeps are tough to deal with, especially in your home yard."

Lincecum (10-9) went down in the eighth inning when Utley's bat skittered back at him. Utley went out to check on Lincecum, who handed back the bat, walked it off and stayed in the game. Utley then hit a one-out single.

Lincecum left later in the eighth after Hunter Pence reached with two outs on first baseman Aubrey Huff's error. Javier Lopez relieved and retired Raul Ibanez on a fly ball.

Brian Wilson finished for his 34th save in 38 chances, closing out the Giants' second win in 10 games.

New Giants star Carlos Beltran left after the seventh. He felt a sharp pain in the top of his right hand on a swinging strikeout to end the sixth. X-rays were negative and Beltran was expected to play Monday night against Pittsburgh.

The NL East-leading Phillies, with the majors' best record at 74-40, hadn't lost since dropping two of three to the Giants in Philly from July 26-28.

Lincecum allowed seven hits and one run, struck out five and walked one in 7 2-3 innings. The two-time NL Cy Young Award winner and four-time All-Star beat the Phillies for the second time in three starts. After walking leadoff man Jimmy Rollins on four pitches to start the game, Lincecum worked from the stretch the rest of the way to "simplify things."

He was determined to get the Giants back on track.

"With the funk we've been in, you hope this is something to build on," Lincecum said. "We don't want to be content just winning one here and there."

It was a timely performance for the reigning World Series champions, who have been struggling to score enough runs for their talented pitching staff. San Francisco held its half-game lead on Arizona in the NL West after the Diamondbacks beat the Dodgers.

"He gave us what we needed," manager Bruce Bochy said.

Oswalt (4-7), facing Lincecum in their seventh career regular-season meeting, gave up a season-high 12 hits in his first start since June 23. The right-hander missed 37 games with lower back inflammation. He is 1-7 since beginning the year 3-0.

"That was better than I thought I was going to be," he said. "It wasn't like I was giving up doubles into the gap. It feels good to be back on the field. Hopefully I can finish out the year."

Phillies slugger Ryan Howard went 1 for 12 with eight strikeouts in the series and was 3 for 24 in seven games against the Giants this year. He struck out 12 times in 22 at-bats last October when San Francisco beat Philadelphia in the six-game NL championship series.

Orlando Cabrera hit a go-ahead sacrifice fly in the fifth and Keppinger added one of his own in the sixth.

The Giants produced 13 hits and avoided their first four-game sweep by the Phillies since losing in Philly from May 13-16, 1982 — and at home since Aug. 6-8, 1943, while playing in New York.

Chris Stewart added a pair of singles and an RBI and Pablo Sandoval had two hits for San Francisco, which loaded the bases against Oswalt in the fourth. Stewart delivered a single up the middle to tie the game at 1. The Giants finally made the most of some chances after going hitless in their first 18 at-bats of the series with runners in scoring position.

Huff's fourth-inning bloop single two batters ahead of Stewart ended an 0-for-22 stretch overall with runners in scoring position.

Beltran was booed when he hit into an inning-ending double play in the first. But Phillies center fielder Shane Victorino, in the middle of the skirmish Friday, got it worse from the sellout crowd of 42,366 — and fans jumped to their feet and roared when he struck out looking in the third.

"You know what, nothing compared to New York," said Beltran, traded to the Giants on July 28 from the Mets.

Phillies catcher Carlos Ruiz took a third-inning foul tip by Lincecum in the facemask but stayed in the game after being examined by trainers. He had two hits.

NOTES: Phillies 3B Placido Polanco flew home to Philadelphia to undergo an MRI exam Monday on his sore left hip. He came out of Saturday's game with the injury, which he said had been bothering him for some time and wasn't a result of being tackled by Giants catcher Eli Whiteside during the fracas Friday. ... Oswalt had his third hit of the year with a leadoff single in the third. ... San Francisco INF Miguel Tejada will likely go on a short rehab assignment soon before returning from the DL with a lower abdominal strain. ... Giants LHP Barry Zito's rehab outing with Class-A San Jose was pushed back from Sunday to Monday. He is likely to pitch four or five innings as he nurses a sprained right foot that also sidelined him earlier this year. ... Giants RHP and All-Star Ryan Vogelsong (9-1) tries to extend his career-best winning streak to seven straight decisions in Monday night's series opener against the Pirates. He is 6-0 with a 2.50 ERA over his last 12 outings. Vogelsong won at Pittsburgh in his first start of the year April 28, allowing two runs on four hits in 5 2-3 innings. He matched his career high with eight Ks. ... The Phillies continue their 10-game road trip against the NL West with the opener at Dodger Stadium. Roy Halladay (14-4) looks to win his fourth straight start. Philadelphia is headed into Game 18 of 20 in a row without a day off.