Updated

SAN FRANCISCO (AP) — Wilson Valdez doubled home the go-ahead run in the 11th inning, Jayson Werth's three-run double with two outs in the ninth rallied Philadelphia after Tim Lincecum left the game, and the Phillies beat the San Francisco Giants 7-6 on Wednesday to avoid their first sweep of 2010.

Ryan Howard snapped a career-high 65 at-bat homerless streak in the fifth when he sent the first pitch from Lincecum into the left-field seats. It was Howard's first homer since agreeing Monday to a $125 million, five-year contract extension.

Lincecum, the two-time reigning NL Cy Young Award winner, struck out 11 in outdueling Cole Hamels and was poised to win his fifth straight start to begin the year until closer Brian Wilson blew it.

Nate Schierholtz had an RBI double in the bottom of the 11th for his career-high fifth hit but it wasn't enough on a day the Giants stranded 16 baserunners.

Ryan Madson (1-0) pitched one inning for the win despite allowing an RBI single to Andres Torres in the bottom of the 10th, Torres' third RBI of the game. Nelson Figueroa finished for his first career save.

Schierholtz's 11th-inning double moved Juan Uribe — aboard on a pinch-hit single — to third and brought up Eugenio Velez. He grounded into a fielder's choice to first and Howard threw home to save the tying run on a close call at the plate.

The Phillies added an insurance run in the 11th on Velez's fielding error in left when he dropped a routine fly by Shane Victorino.

Brian Schneider scored for Philadelphia in the top of the 10th on a wild pitch. Sergio Romo (0-2) was the loser.

The homer by Howard was just the second of the year allowed by Lincecum, and Howard's three career clouts against the Giants' ace are the most by anyone.

Lincecum had thrown 98 pitches when he went out to start the ninth but was done after a one-out walk to Victorino. Fans booed when manager Bruce Bochy removed the right-hander. Wilson then blew his first save in five chances.

Lincecum and Hamels combined for 21 strikeouts. Torres drew a go-ahead, bases-loaded walk from Hamels in the sixth and also hit a tying RBI double in the fifth, but the bullpen couldn't keep a 4-1 lead.

Lincecum struck out the side in the second and reached double digits in strikeouts for the 21st time and the second this year. Hamels did so for the 13th time and first in 2010.

After Torres' walk in the sixth, Edgar Renteria followed with a two-run single.

Howard hit a two-out double to right in the seventh, sliding in to make sure he was safe after Schierholtz threw him out when he slowed up on a similar play during a 6-2 loss Tuesday night.

The reigning NL champion Phillies avoided their first four-game skid since dropping four straight at Houston last Sept. 4-7. They fell out of at least a share of first place in the NL East for the first time all season Tuesday night and wrapped up a disappointing 4-5 road trip.

Lincecum retired the first 10 batters of the game before Placido Polanco lined a one-out single to right in the fourth. Chase Utley then grounded into an inning-ending double play, so Lincecum faced the minimum through four.

Utley singled off Wilson for hit No. 1,000 of his career.

Notes: Phillies SS Jimmy Rollins has begun jogging again, but wasn't sure when he would start true running as part of his recovery from a strained right calf that landed him on the disabled list April 14. "I'm not going to rush it this time. I rushed it last time," he said in reference to an ankle injury in 2008. "But we won a World Series." ... Several Giants players, including slugger Pablo Sandoval, were headed to "Homecoming Night" hosted by the Class-A San Jose team to honor those players who have gone on from that club to reach the big leagues. ... Injured Giants 2B Uribe, who hasn't started since exiting early in Saturday night's game against St. Louis, expects to return to the lineup Friday night against Colorado after Thursday's day off. "I'm much better," he said. "Not quite 100 percent, but close."