BOSTON - The Phillies can only hope that they have learned whatever lesson the cosmos had in store, that they have have completed their time in purgatory, that they have finished their walk through the valley of the shadow of death.

The Ghost of Offensive Slump Past became the Ghost of Offensive Slump Present yesterday afternoon, and maybe it's what the Phillies needed - to stare down and make peace with the man who helped knock, or knuckle, them into their current funk.

"I'll believe in anything right now," leftfielder Raul Ibanez said after Cole Hamels pitched seven strong innings and the Phillies beat Tim Wakefield and the Red Sox, 5-3, to snap a three-game losing streak and avoid being swept at Fenway Park.

They didn't exactly force Wakefield to run shrieking into the Charles River, but they did score four runs off him in the fourth inning, which was four more than they scored in eight innings against him back on May 23, when he sent the Phillies spiraling into a dense offensive fog that has yet to lift.

Over the next 17 games, they scored just 40 runs, and after yesterday's win sat in third place in the NL East with a 32-29 record, 3 1/2 games behind first-place Atlanta. In the first two games of the series at Fenway Park, they had been outscored by 22-4.

For the most part, yesterday's victory brought more of the same. Five of their seven hits off Wakefield came in the fourth inning, including a two-run homer by Ibanez. After Juan Castro's single scored Ben Francisco and gave the Phillies a 4-1 lead, Wakefield retired the next 11 hitters he faced. In the first inning, the Phillies had loaded the bases with no outs but failed to score as Howard flew out and Jayson Werth grounded into a doubleplay.

"It was really just that one inning, I think," said Ibanez, who homered for the first time in 27 games and now has nine hits in his last 23 at-bats, raising his average from .229 to .247 in six games. "We were able to score some runs and get to him a little bit, and then he adjusted to us and started doing some different stuff with that knuckleball. I mean, he's a master with it."

Said Howard, who doubled and scored on a Werth single in the fourth: "I think it was a matter of just getting more pitches to hit, and making his knuckleball start up. Later in the game, he started throwing an even slower knuckleball."

The Phillies had two things working for them. First, they took advantage of Wakefield's lapses.

"That's when you better get him," manager Charlie Manuel said.

Second, they had a master of their own on the mound in Hamels, who relied on a faster-than-usual fastball to hold the Red Sox to one run on five hits and two walks in seven innings.

Aside from a leadoff homer by Adrian Beltre in the second inning, which came on a hanging slider, Hamels looked dominant. He had eight strikeouts while consistently touching 95 mph with a fastball that usually sits in the 90-92 range.

After losing a hotly contested 15-pitch at-bat by walking Victor Martinez in the sixth, he recorded the next three outs with two runners on, then pitched a scoreless seventh and handed the game over to Jose Contreras, J.C. Romero and Brad Lidge.

The Red Sox added two runs in the ninth when Romero gave up a double and a walk, and Lidge gave up a single, but Lidge retired two hitters to close out his fourth save of the year.

"[Hamels'] composure has been very good," Manuel said. "That was big for us. Real big. We needed to win a game. We need to start playing better. That was big. Huge."

Now, with six more games against American League heavyweights on tap for this week, the Phillies will attempt to finally turn the corner they have been facing for the last 3 weeks.

They exorcised one demon yesterday. With a three-game series against the Yankees up next, they have a chance to exorcise another one.

For more Phillies coverage and opinion, read David Murphy's blog, High Cheese, at http://go.philly.com/highcheese.