The Baltimore Orioles had just blown a four-run lead against the Boston Red Sox in the eighth inning, and for an instant there was a here-we-go-again feeling in the dugout.

"It was a sense of, 'Aw, dang it,'" left fielder Luke Scott said. "It took about a second to reflect on it, but guys were upbeat, guys were positive, guys were optimistic. We were up there ready to go."

After overcoming one more setback in the wild eighth inning, the Orioles scored the go-ahead run on an RBI single by Vladimir Guerrero and came away with a 5-4 victory Wednesday night.

In the top of the inning, Adrian Gonzalez singled in a run and Kevin Youkilis followed with a three-run homer off Koji Uehara (1-0).

It was a bitter blow for the Orioles, a team mired in a run of 13 straight losing seasons and accustomed to being fodder for the Red Sox.

"We've taken our licks. We know what it's like to lose, get our butts beat and get buried. It's not fun," Scott said. "But at the same time, through the adversity we've learned to play hard, regardless of the circumstances. It's carrying over to now, where we've gotten better as a team."

Nick Markakis opened the Baltimore eighth with a single off Daniel Bard (0-3), and Derrek Lee followed with a single to left. Both moved up on a passed ball by Jason Varitek, and with Guerrero at the plate, Markakis was thrown out trying to score on a pitch that eluded Varitek.

"That's a big karma change in that game," Orioles manager Buck Showalter said, "because it looked like they had an opportunity to potentially get out of it."

Not this time. Guerrero bounced an RBI single up the middle to bring in Lee from third base, putting Baltimore back in front.

Kevin Gregg worked a perfect ninth for his fourth save.

By winning the first two games of the three-game set, the Orioles captured their first series since taking two of three against Detroit on April 4-7. Baltimore has won 11 of 18 against the Red Sox after going 3-25 from July 12, 2008 through April 24, 2010.

In the middle of the eighth, though, the outcome was suddenly in doubt.

"We got back in the dugout, the whole team was frustrated," center fielder Adam Jones said. "So a lot of guys were just saying, 'Let's go. Let's go.'"

In the top half, Jacoby Ellsbury singled and Dustin Pedroia walked against Jeremy Accardo. Gonzalez hit an RBI single off Clay Rapada, Uehara entered, and Youkilis hit a 2-1 pitch into the left-field seats to tie it.

"It was kind of a roller coaster that turned in a hurry for us," Boston manager Terry Francona said. "We were scrambling, not doing much offensively, then (Youkilis) gets the home run. Then we give up a run. It's a tough loss, it hurts."

Orioles starter Jeremy Guthrie gave up seven hits, walked one and struck out six in six shutout innings. He left with a 4-0 lead, but the Baltimore bullpen ruined his bid to end a seven-game losing streak against Boston.

Guthrie outpitched Josh Beckett, who allowed four runs and seven hits in six innings. The right-hander permitted only three earned runs in his previous three starts and surrendered only one homer in 31 innings this season before Luke Scott and Jones connected in succession in the fourth.

Both starters were in control until Lee hit a popup to right field with one out in the fourth. As a result of an apparent miscommunication, the ball landed between second baseman Pedroia and Ellsbury, the center fielder.

"Obviously, that's a huge play any time you give them an extra out," Francona said. "It's not an error, but we didn't catch the ball."

One out later, Scott hit a 1-0 pitch over the 25-foot scoreboard in right. Jones followed with a drive to left that was touched by a fan in the front row of the stands before Carl Crawford could try to catch it.

A sacrifice fly by Brian Roberts made it 4-0 in the fifth.

In the fourth, Boston's David Ortiz tried to score from second on a two-out single to right by Jed Lowrie. Markakis unleashed a throw that hit catcher Matt Wieters on the fly, and Ortiz was tagged out at the end of an awkward slide.

NOTES: Crawford bounced into a rare double play to end the second inning for Boston. It was the first time in 87 at-bats this year that he hit into a DP; last season he hit into two double plays in 600 official at-bats with Tampa Bay. ... Lee had a season-high three hits. ... In the 20-year history of Camden Yards, Scott has hit five of the 53 home runs that have landed on Eutaw Street. ... Roberts' 12-game hitting streak ended.