BALTIMORE – 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.

“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 a 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 get out of it.”

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

By winning the first two games of the three-game set, the Orioles captured their first series since taking 2 of 3 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 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. Beckett permitted only three earned runs in his previous three starts and surrendered only one homer in 31 innings this season before Luke Scott and Adam Jones connected in succession in the fourth.

Both starters were in control until Lee hit a pop 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 before Carl Crawford could try to catch it.