BALTIMORE -- Everything went right for the Rays Wednesday night -- except for the bottom of the ninth.

Fortunately for the Rays, they had built enough of a cushion to weather the storm, taking an 8-6 win over the Orioles in front of a crowd of 13,237 at Camden Yards.

With the victory, the Rays snapped a two-game losing streak to finish their road trip with a respectable 4-3 mark while avoiding last place in the American League East, which is where a loss would have landed them.

"The strange part about this, what's different, is we come home from this 4-3 and we're disappointed," Rays manager Joe Maddon said. "There's so many other games we feel as if we could have won on this trip. And it's a tough trip -- New York, Boston, Baltimore -- and we're still going home successful, but not pleased entirely. And that's a good thing.

"We have our sights set so much higher now. And to be able to pull it out is great. ... But we know we still have a ways to go to get back to where we want to be. To win under these circumstances and come out with a winning record is pretty good in spite of the fact we're still not playing our best baseball."

A lot went right for the Rays Wednesday night, due primarily to effort.

Carlos Pena set the tone for the evening in the bottom of the first, when Melvin Mora popped up along the Orioles' dugout. Both Pena and catcher Dioner Navarro hustled over to try to make the play. The ball looked unreachable, but Pena extended himself over the railing to make the catch, upending himself in the process.

Later Carl Crawford made a diving catch on Aubrey Huff's sinking liner to end the fourth. He sustained a bruised right shoulder on the play and left the game after batting in the fifth. Ben Zobrist took over in left field.

And while the Rays did not get the number of innings they would have liked to have gotten out of starter Jeff Niemann, he did show vast improvement over his previous two outings. The 6-foot-9, 280 pound right-hander held the Orioles to two runs on eight hits in five innings to earn his third win of the season.

"Tonight was a lot better than the past two have been," Niemann said. "I just have to kind of build off this. ... [The biggest difference] was just being able to throw the breaking ball for strikes."

Finally, when the Rays had the chance to put the Orioles away in the top of the ninth, they did, exercising stellar plate discipline to draw three walks from reliever Bob McCrory and scoring on a wild pitch and RBI singles from Navarro, B.J. Upton, and Zobrist to push the lead to 8-2.

"That was great," Maddon said of the ninth inning. "A lot of ground-ball base hits, we keep talking about that. ... [We were] much better in situations, not trying to hit home runs, trying to score the run. We did a good job of moving the guys around the bases. We need to do more of that, obviously. Not trying to just hit home runs, and I liked that a lot."

The bullpen came through again with another stellar effort by Lance Cormier, Brian Shouse and Dan Wheeler that got the team through eight innings. The excitement came in the bottom of the ninth, when Troy Percival entered the game to make his 700th career appearance and the bottom nearly fell out.

The veteran closer immediately gave up a double to Cesar Izturis before surrendering a two-run homer to Brian Roberts. Felix Pie followed with a solo shot to cut the lead to 8-5. One out later, Huff doubled to right to chase Percival in favor of J.P. Howell.

"I felt good and there was no excuse for it," Percival said. "I was just getting underneath the ball, which I didn't think I was doing down in the bullpen.

"But that's the strongest my arm has felt in two years. And I was just throwing the ball down the middle. I guess I should have treated it more like a one-run game and really focused on hitting my edges and what have you."

Melvin Mora greeted Howell with an RBI single to cut the lead to 8-6 before getting Lou Montanez and Ty Wigginton to each hit into a fielder's choice to end the game.

"I'll never be upset if we win the game," Percival said. "If we'd have lost that game I'd have been pretty upset."

Percival flipped the baseball commemorating his 700th appearance to Niemann with a smile; he did not want the ball as a keepsake. Despite his performance, he could look ahead and where the team is at this point of the season.

"Obviously, we'd like to be in a better position than we are," Percival said. "But if you look at where we've been and the travel that we've done and who we've played ... you'd like to come out a little above .500 and we're not. But we're in striking distance. And we get to play where we play really well, at home."