The San Francisco Giants completed a trade Tuesday to acquire outfielder Hunter Pence from the Philadelphia Phillies in exchange for outfielder Nate Schierholtz, Double-A catcher Tommy Joseph and Class A pitcher Seth Rosin.

It's the second time in two years Pence went from last place to first place right before the non-waiver trade deadline.

"Thank you Philadelphia for all your support and passion. Excited to see what awaits me in San Francisco!" Pence wrote on Twitter.

The Phillies had been actively shopping Pence, who is under contract for $10.4 million this season and is expected to earn in excess of $13 million in 2013. Pence is hitting .271 with 17 homers and 59 RBIs for Philadelphia this season. He led the Phillies in hits, homers, RBIs, runs scored and walks.

"He's a dynamic player," Giants catcher Buster Posey said. "He's not only going to help us with his bat, but just with the energy he brings."

Philadelphia acquired Pence from Houston on July 29 last year for the same reason San Francisco wanted him. The Phillies were desperate for a right-handed power hitter to bat fifth behind Chase Utley and Ryan Howard. Pence fit the description perfectly. He batted .324 with 11 homers and 35 RBIs in only 54 games for Philadelphia.

Schierholtz is hitting .257 with five homers and 17 RBIs in 77 games. The left-handed hitting right fielder likely will get more playing time in Philadelphia the rest of this season. He hit .270 with 23 homers and 119 RBIs in 503 games over parts of six seasons in San Francisco. Schierholtz was 2 for 12 in the 2010 postseason when the Giants upset the Phillies in the NLCS and beat Texas in the World Series.

The Phillies sent outfielder Shane Victorino to the Los Angeles Dodgers earlier Tuesday.

Philadelphia won a franchise-record 102 games last season, but has fallen out of contention this year.

"I don't think anyone really anticipated the season that's gone on," Pence told reporters in Washington after the trade. "It was the perfect storm of injuries and things didn't go right for us, so that's the way the business of the game is and you have to understand that.

"Everything is understood. The Phillies are going in a different direction. We had a great run at it. Now I'm going a different way."