Updated

San Diego, CA (SportsNetwork.com) - Buster Posey smacked a two-run homer in the first inning and the San Francisco Giants held off the San Diego Padres, 4-3, in the finale of a three-game set.

Angel Pagan had a two-run single in the following frame for San Francisco, which halted a three-game losing streak.

Tim Lincecum (1-1) struck out seven and allowed three runs on seven hits and three walks over six frames to notch the win. Sergio Romo fired a scoreless ninth to pick up his fifth save of the season.

"I just kind of got us off on a good foot today. I think that is something our offense has been looking for, to get them kind of generated," said Lincecum. "I just did my best to keep us in the game."

Nick Hundley cracked a solo shot among his two hits for the Padres, who had won five of their last seven tilts coming in. Robbie Erlin (1-2) surrendered four runs on three hits and three walks over six frames in the loss.

"After a shaky start he hung in there and showed a lot of character. He didn't cave in, didn't melt and put up four zeroes. I liked that about Robbie," Padres manager Bud Black said.

The Giants plated a pair of runs in the first and second to jump out to a 4-0 lead.

Hunter Pence worked a one-out walk in the first before Posey launched a towering shot into the San Francisco bullpen in left-center field.

San Francisco loaded the bases with one away when Brandon Hicks walked, Brandon Crawford singled and Lincecum was issued a free pass. Pagan then plated Hicks and Crawford with a base hit into right-center.

San Diego got two runs back in the third on Chase Headley's two-run double, and Hundley's leadoff blast to left in the seventh trimmed the deficit to 4-3.

The Padres, though, never threatened over the final two innings.

Game Notes

Posey has four homers and 10 RBI, while Pagan has tallied 12 RBI so far this season ... San Francisco was 1-for-4 with runners in scoring position, while San Diego finished 1-for-7 with RISP.