Casilla's long ball -- his first of the season -- was preceded by first baseman Chris Davis' game-tying two-run shot, and kept the crowd at Camden Yards on its feet.
And in return, the Orioles -- who had been dominated by Masterson over the first half of the game -- got back on theirs.
"It was awesome," Davis said of watching Casilla connect for his first homer since Aug. 8, 2012 -- also, as coincidence would have it, off Masterson. "I think everybody's pulling for him right there, obviously trying, hoping that he'll just get a base hit. Then he does that, provided a little bit of a jolt of adrenaline for everybody."
The victory keeps the Orioles (43-35) on pace in a tough American League East. And for that the thanks goes to starter Chris Tillman, who struggled with command and battled through seven innings, helping to save an overworked bullpen and giving one of baseball's most lethal lineups a chance to get to work en route to his career-high sixth consecutive win.
"Tilly's a good teammate," Showalter said of the 25-year-old, who improved to a staff-leading 9-2. "As you get to know him, there's a lot beating in there. Very competitive guy.
"It was kind of tough when we were making three up, three down real quick [against Masterson], and he went out there and got into some deep pitch counts, it seemed, like every inning. And once he got in step, you saw him really get after it. ... He gives you that look. He won't tell you he's ready to come out of a game, but for the right reasons. He's sincere."
Having thrown 39 pitches through two innings, Tillman labored early and tied a season high with four walks before recording an out in the third. Still, he was able to minimize the damage, allowing only one run on a bases-loaded spot in the first and a two-run homer on a changeup to the red-hot Jason Kipnis before departing the six-strikeout outing.
"It was definitely a grind for me," said Tilman, who threw 95 pitches. "I was off the first couple of innings. I found a way to get back into it. ... I give credit to [catcher Matt] Wieters. I don't know how he does it sometimes, but he did an outstanding job getting me back on track tonight, and he was able to keep it close."
The O's finally broke through in the bottom half of the seventh. Masterson, who retired the first 12 consecutive batters he faced before the O's pieced together a fifth-inning run, hit leadoff man Adam Jones with a pitch, and Davis made him pay.
Davis continued his torrid season, blasting the first pitch into the right-field stands to extend his Major League lead in homers to 28 and notch 72 RBIs on the season.
Wieters followed with a walk and, one out later, Chris Dickerson singled to bring up No. 9 batter Casilla.
"To help the team win a game, it felt, for me, really good," Casilla, who had struck out in his prior two at-bats, said through interpreter Einar Diaz.
Casilla's homer chased Masterson from the game, and it held up as the decisive mark.
"It's a good lineup," said Masterson of the Orioles. "We had been working well through six innings and, unfortunately, we got to the seventh."
Reliever Troy Patton followed Tillman with a scoreless eighth, and closer Jim Johnson picked up his 27th save, which leads the Majors.