SAN FRANCISCO - Whether it was the near-constant trade buzz or the pitcher coming into his own in a season the began with his arm behind schedule, Cole Hamels may have been baseball's best pitcher in the last month.

He took the mound on Friday at AT&T Park with a 0.73 ERA in his last five starts. Hamels hadn't allowed more than one run in a start since July 12; even two-Time Cy Young winner and current 2014 National League favorite Clayton Kershaw couldn't match that in the last month.

But given his paltry run support in the last 2 years, Hamels has pretty much had to be that close to perfect to give the Phillies the chance to win. Despite that 0.73 ERA in Hamels previous five starts, the Phils had lost each of the last two games he had started.

A similar script played out over the course of the first seven innings, with Hamels serving up a three-run home run and his teammates offering little in the form of a response.

But the Phillies rallied to tie the game in the eighth and claimed their first lead in the 10th en route to a 5-3 win over the Giants.

"A good comeback win," manager Ryne Sandberg said.

The victory was due in part to Sandberg giving his young third baseman an opportunity against one of the National League's top lefthanded pitchers. Three weeks since resting Cody Asche against Madison Bumgarner, Sandberg slotted his regular third baseman in the lineup against the Giants All-Star lefty.

Asche was hitless against Bumgarner, but his bat fueled the comeback win. Asche slugged a game-tying home run in the eighth and ignited the game-wining rally in the 10th, too.

"He got a pitch and he nailed it," Sandberg said of the home run, only the third of his career off a lefthanded pitcher. "We just had the day off. To be a regular guy, to get a chance to be a regular player you face lefthanded pitching."

With the two teams knotted at 3-3, Asche led off the 10th with a double to left-center off righthander Santiago Casilla. He moved to third when Andres Blanco followed with a sacrifice bunt. After Ben Revere flew out, Javier Lopez walked Jimmy Rollins on four pitches to load the bases.

Javier Lopez' first pitch to Chase Utley caught the second baseman in the left pant leg, bringing home the go-ahead run. Ryan Howard provided a run of insurance when he followed with a sacrifice fly.

"Just a little tick; we'll take it," Sandberg said of the pivotal hit by pitch. "Of course, he's not going to jump out of the way, either. That's what I like about it."

Friday's come-from-behind victory marked only the fifth time this season the Phils won a game that they trailed after seven innings. The Phillies were 4-56 in such games entering the night.

The late-arriving offense saved Hamels from defeat.

Hamels matched Bumgarner for three innings before serving up a three-run home run to Michael Morse in the fourth.

Considering the offense has scored four or more in only 23 of Hamels' starts since the beginning of last year, the 2-1 changeup that Morse deposited over the fence in center felt like it would seal the fate of the Phillies and their ace.

But then a couple of home runs led the comeback.

Marlon Byrd's 23rd home run of the year, leading off the fifth inning, provided the Phillies with their first run of the night. But Bumgarner, who had posted back-to-back complete games entering the night, responded by retiring nine of the next 10 batters.

In the eighth, fellow lefthander Jeremy Affeldt took over for Bumgarner, who threw 110 pitches in seven inning. Darin Ruf led off the inning with a single, his second hit of the night, before Asche nearly found McCovey Cove.

Asche eyed up a 3-1 fastball up and over the heart of the plate and launched a game-tying, two-run home run to right. Asche's eighth home run of the year was the first Affeldt had served up to a lefthanded hitter in more than three years (Atlanta's Jason Heyward on April 24, 2011).

The home run was also only the second for Asche since July 5, a span of 128 plate appearances. He entered the night mired in a 2-for-26 funk and extended it by going hitless in two at-bats against Bumgarner.

But then Affeldt left a ball up and Asche connected, leading the comeback charge.

"About time, huh?" Asche said.

On Twitter: @ryanlawrence21