The Orioles remained tied at the top of the American League East with the New York Yankees and they moved three games in front of third-place Tampa Bay.
The Rays had a chance to break a 2-2 tie in the top of the ninth when pinch-runner Rich Thompson tried to score all the way from second on an infield single by Evan Longoria.
Thompson, however, was thrown out at home and Baltimore quickly took advantage in the bottom half of the inning.
Kyle Farnsworth (1-5) went to the mound in the ninth for the Rays and he threw only four pitches. The first one was hit to left for a single by Machado, the second one turned into a sacrifice bunt by Robert Andino and the fourth was sent up the middle for a single by McLouth to end the game.
Jim Johnson (2-1), who escaped the trouble in the top of the ninth, picked up the win.
Baltimore won for the seventh time in 10 games, getting RBI singles in the first inning from Matt Wieters and Wilson Betemit.
Celebrity Couples of 2014 [PHOTOS]