Buster Posey had four hits to extend his hitting streak to 18 games and Travis Ishikawa drove him in with a run-scoring single in the 10th inning, helping the San Francisco Giants beat the Diamondbacks 3-2 on Sunday to complete their first four-game sweep in Arizona in nine years.

The Diamondbacks, who traded All-Star right-hander Dan Haren during the game to the Los Angeles Angels for three pitchers and a player to be named, had runners on the corners in the ninth, but Sergio Romo (3-3) struck out Cole Gillespie and Chris Young.

Posey started the winning rally with a double, setting up Ishikawa's single off Esmerling Vasquez (1-3) that easily scored pinch-runner Eli Whiteside and gave the Giants their first four-game sweep in Arizona since July 26-29, 2001.

Posey also drove in two runs and passed Orlando Cepeda for the second-longest hitting streak by a Giants rookie, leaving him four behind Willie McCovey's 1959 record.

Brian Wilson pitched a perfect 10th for his 29th save in 31 chances.

The last-place Diamondbacks were looking to move Haren's big contract ahead of the July 31 non-waiver trading deadline. In return for the three-time All-Star, Arizona acquired left-hander Joe Saunders and right-hander Rafael Rodriguez, along with minor leaguer Patrick Corbin, from the Angels.

Haren has averaged 15 wins over the past five seasons and is 7-8 with a 4.60 ERA in 21 starts this year. He was tied for the NL lead with 141 strikeouts through Saturday's games.

Justin Upton had three hits to extend his hitting streak to 12 games for Arizona, which had runners on third with one out in the eighth and ninth innings but couldn't score.

Starter Tim Lincecum made a similar escape in the eighth, getting Adam LaRoche to hit a too-shallow fly to left and a double play when third baseman Juan Uribe snared Miguel Montero's liner and doubled off Justin Upton at first.

The Giants were playing thin with outfielder Eugenio Velez on the mend and third baseman Pablo Sandoval headed to Venezuela for a couple of days.

Velez was struck on the head by a foul ball in the dugout against the Diamondbacks Saturday and spent the night in the hospital. He has a concussion, but was expected to travel home with the team. Sandoval went home to attend to a personal matter and was expected to return by Tuesday, at the latest.

Lincecum did his best to keep the Giants from needing them in the lineup, regaining his command after a shaky outing against the Dodgers on Tuesday.

The player the two-time NL Cy Young winner had the most trouble with was Diamondbacks pitcher Barry Enright, who had one career hit before Sunday. The rookie knocked San Francisco's ace for a two-run double for his first extra-base hit and added a single in the fifth.

Linecum was good against everyone else, wriggling out of the jam in the eighth before being replaced by Romo in the ninth after allowing two runs on nine hits.

Enright did his part, limiting the damage of eight hits and three walks over six innings. Posey was the only one to hurt the right-hander, hitting a run-scoring double in the first inning and an RBI single in the fifth that tied the game at 2.

Enright allowed two runs, the fifth straight start he's given up three or less.

NOTES: Giants 2B Freddy Sanchez made a sliding stop and threw out Montero from his backside in the second inning. ... Upton is 20 for 47 with nine doubles during a 12-game hitting streak. ... The Giants hadn't swept the Diamondbacks anywhere since July 21-24, 2003.