BALTIMORE -- Daisuke Matsuzaka's record-setting night transpired predictably through seven innings as he battled Orioles ace Erik Bedard on Friday.

But the pitchers' duel quickly transformed into a slugfest, and Dice-K's brilliant start was overshadowed by the 10 runs posted by the teams in the final two innings and a dramatic 6-5 Red Sox loss in front of the largest crowd of the season at Camden Yards.

Dice-K struck out seven batters to set a new Boston rookie record with 159 punchouts this season and held Baltimore in check just as he has done to opposing offenses all season. But after he matched Bedard's 7 2/3 lights-out innings and left the game, the low-scoring nail-biter became a hit parade.

Trailing, 1-0, in the eighth inning, Boston mounted a furious comeback and posted five runs, all with two outs, to storm to a 5-1 lead. But Baltimore put together a charge of its own in the eighth inning and responded with four runs off reliever Eric Gagne to knot the game at 5.

In the ninth, Baltimore used a ground-rule double off the bat of second baseman Brian Roberts and a sacrifice fly against Hideki Okajima to clinch the victory.

"They both pitched great," Boston manager Terry Francona said of Bedard and Matsuzaka's masterful outings. "It was kind of a roller-coaster game. We were scratching just to get one and then we have an inning where we really put together a good inning. Then they did the same thing to us."

Boston amassed just two hits over the first seven innings against Bedard, who leads the Majors with 199 strikeouts. But right fielder Willy Mo Pena drove the Baltimore starter from the game in the eighth inning, when he slapped a Bedard offering up the middle to drive in catcher Jason Varitek and tie the game. One pitch later, shortstop Julio Lugo eased a perfectly-placed bunt past reliever Chad Bradford and put Boston on top before it charged to a 5-1 lead.

The Orioles then used three hits, including two doubles, and a walk off Gagne to swing the momentum back in their favor. By the time Francona opted to put Okajima on the mound, it was too late. Melvin Mora singled in the tying run, and Gange inherited all four eighth-inning tallies.

"I'm not locating my fastball, not locating my changeup, not locating my curveball and not making my pitches when I have to," Gagne said. "I've got to step it up and do my job and get people out. There's no excuse.

"I don't know what else to tell you guys. I'm not making my pitches. I'm not throwing the way I should throw. I'm not doing my job right now, and it's making it hard on everybody else."

Gagne made his fourth appearance in a Red Sox uniform after being acquired from Texas on July 31. He's now allowed six runs on nine hits in those games. While he said the trade isn't a reason for his struggles, Francona pointed out the move after the game.

"Any time you have walks mixed in with hits, things look worse," Francona said. "He got into hitters' counts, and I'm sure this is an adjustment. It just got at him."

The loss dropped the Red Sox's record to 49-7 when they score five or more runs and snapped a streak of 11 straight victories when they post at least a five-spot on the scoreboard.

The overall look of bewilderment that several Red Sox players donned after the game was perhaps apparent on Gagne's face more than anyone else's. He sat, facing his locker 10 minutes after the game, and his teammates seemed to share his feelings.

One such player was J.D. Drew, who entered the game to pinch-run in the eighth and misplayed an Aubrey Huff double that allowed two runs to score in Baltimore's late comeback.

"There were some hard hit balls and that was another line drive coming right at me," Drew said. "It's one of those do-or-die plays. I thought for sure I had a chance at the ball but it had a lot of topspin on it and it took a crazy hop."

"It's just one of those games," Drew continued. "The situation at the end you never would have predicted. We battled back and got some runs, but it was tough."

For Dice-K, whose strikeout record became yet another accolade tacked onto his outstanding rookie season, his personal performance took a back seat to the current state of affairs. With the Yankees' win Friday, the Red Sox's lead in the American League East was trimmed to five games. They haven't led by less than five games since May 2.

"We're at a point in the season where we want to pick up every win we can, especially going late into the game with a lead like that," Matsuzaka said through an interpreter. "So the fact that we weren't able to hang on today was a big disappointment."