"I was so proud of the guys tonight," manager Buck Showalter said. "They just kept grinding. They're not going to be denied."
The Orioles took leads in the first, sixth and seventh innings, only to see the Indians fight back every time.
O's starter Jake Arrieta said all of the pitchers struggled to get a grip on the ball -- he could hardly find a dry spot on his sweat-soaked uniform -- leading to hits and runs in bunches.
Arrieta allowed five runs on eights hits while tying his shortest outing of the season at just 3 2/3 innings, although a misplay of a fly ball between Flaherty and Adam Jones in the fourth inning played a role in his struggles. Showalter said he felt Arrieta deserved a better fate, and both the manager and the starter said he suffered from a few "borderline calls."
But even as Arrieta faltered and normal shutdown relievers Troy Patton, Darren O'Day and Jim Johnson all surrendered runs, the Orioles clawed their way to a win.
"A lot of mental toughness showed itself in this game tonight," Showalter said. "Guys didn't give in, and I'm real proud of them. They never got into, 'Woe is me, here we go again.' They just kept grinding and found a way."
For 10 games, the Orioles' offense had been knocking on the door, and in the sixth inning, Matt Wieters finally busted it down.
The O's entered 3-for-52 with runners in scoring position in their last 10 games and started 1-for-7 on Friday. But when Wieters -- batting seventh for the first time all season -- came up with runners on first and third in the sixth, he needed only one pitch to buck that trend, blasting a 395-foot homer onto Eutaw Street to turn a 5-4 deficit into a 7-5 lead.
After Cleveland rallied to tie the game, little-used Rule 5 Draft pick Flaherty delivered the go-ahead hit in the seventh, singling on a grounder to right to put the O's back in front for the final time. Flaherty entered Friday with only one hit and nine at-bats over the last two weeks.
"It was a battle," Wieters said. "That was a game we really had to work for. We haven't been able to come out on top of those, and we really worked to get that win."
The O's had been suffering from a lack of offense for the past 10 games, leading to a free fall in the standings.
But on Friday they eclipsed three runs for the first time since June 16 -- and by a wide margin -- earning a win that draws them within four games of the Yankees in the American League East.
Avery, playing only his second game since being recalled from Triple-A Norfolk, hit his first-career home run to left in the eighth to provide an insurance run that would ultimately be the difference.
When he ran onto the field for the next half inning to help protect a 9-7 lead, he received a warm reception from the home crowd and wore a big smile the whole way out to left.
"This is about the first unabashed smile we've gotten out of him in the public eye," Showalter said.
"He's probably right," Avery said, laughing when told of the manager's comments. "I felt a little tingly inside."
Johnson surrendered a run en route to his Major League-leading 23rd save, but induced a flyout from Asdrubal Cabrera with two outs and a man on first that landed safely in the glove of Avery.
As Avery stood on the field doing a postgame interview, Jones came running from the dugout and planted a shaving cream pie on him.
"I can still taste the shaving cream on my lips," Avery said. "I've got to say it tastes good, too.
"It really wouldn't have meant a lot if we didn't get a win with it. But we got a win with it, so it means a whole lot."