Hamels pitched eight strong innings and Chase Utley had a tiebreaking RBI single in the fifth inning to lift the Philadelphia Phillies to a 2-1 victory over the San Francisco Giants on Thursday.

Hamels (5-5) got the better of Tim Hudson in a matchup between starters who have combined for seven All-Star appearances. The Philadelphia left-hander gave up six hits while striking out 10 and walking one.

More noted for his changeup, Hamels has found an extra gear for his fastball over his last two starts.

After using it to shut down Atlanta in a 2-1 win last Saturday, Hamels frequently featured a heater that again touched the mid-90’s.

The Giants, who were looking for their first four-game sweep in Philadelphia since 1998, lost for just the second time in eight games. San Francisco’s lead over the idle Dodgers in the NL West dropped to 1 1/2 games entering this weekend’s three-game series between the rivals at AT&T; Park.

Despite the defeat, the Giants return home feeling positive after a 5-2 road trip.

“That’s a really good road trip,” Bochy said. “We’ve got a big series ahead of us. It’s going to be a good, exciting series. It’s what you play for.”

Utley, Marlon Byrd and Wil Nieves had a pair of hits for Philadelphia, which snapped its four-game losing streak while winning for just the second time in nine games.

Jonathan Papelbon pitched a scoreless ninth for his 24th save in 27 opportunities to stop a rocky stretch. Papelbon blew his third save in Tuesday’s 9-6, 14-inning defeat and took the loss in Wednesday’s 3-1 loss.

He was booed upon entering the field and then again when he was introduced by PA announcer Dan Baker.

Papelbon pitched a 1-2-3 inning to tie Goose Gossage for 21st place on the all-time save list with career save No. 310.

Philadelphia slugger Ryan Howard wasn’t in the lineup for the second straight day as Sandberg has decided to look elsewhere to find production from first base. Howard has been in a power drought with just one homer since June 19 and his .224 average, .377 slugging percentage and .682 on-base plus slugging mark are well off his usual production.

The move was eye-opening considering the three-time All-Star and former MVP’s dominance against Hudson, against whom he has batted .328 with seven homers and 17 RBIs in 67 career at-bats.

Howard’s replacement, Darin Ruf, went 1-for-4 with a strikeout.

“I wanted to see (Ruf) play for a couple of games, get him some at-bats and basically go from there,” Sandberg said. “We’ll continue to watch.”

Sandberg met with Howard prior to the game, and Howard said he wanted to be in the lineup. But the manager made no promises, adding that a platoon with the right-handed hitting Ruf was possible.

“If he has trouble against left-handed pitching and Darin Ruf is swinging it, that becomes an option,” Sandberg said. “If (a platoon) becomes the scenario and both guys are going well, that’s a good scenario.”

The Phillies got some help on both of their runs off of Hudson.

In the first, Jimmy Rollins hit a one-out double, went to third on a passed ball and scored on Byrd’s single to left.

San Francisco tied the game in the fifth on Ehire Adrianza’s RBI single to center.

Philadelphia got some more good fortune in the bottom of the frame as Ben Revere opened the inning with a medium flyball to left. Michael Morse charged hard but couldn’t come up with the grab and the error allowed Revere to reach second. Revere scored on Utley’s single to center.

Hamels went at least seven innings for the 13th time in the last 15 starts and gave up three runs or less for the 11th consecutive outing. The left-hander reached double-digits in strikeouts for the fourth time this season and 27th in his career.

Hamels cooled off Hunter Pence, who went 0 for 4 with three strikeouts. Pence entered batting .412 with a homer and six RBIs in the series, including the game-winning double in Wednesday’s 3-1 Giants victory.

“I don’t ever recall his fastball being as good as it was today,” Hudson said.

Nieves came up limping after moving awkwardly to block a fourth-inning pitch to Adam Duvall but stayed in the game. Nieves was activated Monday after spending a month on the DL with a strained right quad.

NOTES: Adrianza strained his right hamstring running the bases in the fifth inning. Bochy said he’ll be evaluated further on Friday. … The Giants open a pivotal three-game series at home against the rival Dodgers on Friday with San Francisco right-hander Tim Lincecum (9-6, 3.68) opposing Los Angeles right-hander Zack Greinke (11-6, 2.90). . Philadelphia hosts Arizona for a three-game set that begins Friday when Diamondbacks lefty Wade Miley (6-6, 4.16) takes on Phillies right-hander Kyle Kendrick (4-10, 4.87). . The Giants last swept a four-game series against the Phillies Aug. 30-Sept. 2, 1999, and last did it in Philadelphia July 31-Aug. 3, 1998.