The Orioles trailed by four runs in the seventh and 10-9 in the 12th before rallying to end a four-game skid.
Cesar Izturis led off the 13th by drawing a walk from Lance Cormier (3-2). After a sacrifice, Lugo grounded a single inside the first-base line to bring home Izturis.
Koji Uehara (1-0), the last of six Baltimore pitchers, got the win with 1 1/3 innings of one-hit relief.
B.J. Upton, Matt Joyce and Reid Brignac homered for the Rays, who lost for only the fifth time in 17 games.
The game took 4 hours, 38 minutes.
Both teams scored in the 12th. After Willy Aybar hit a two-out RBI single for Tampa Bay, Corey Patterson opened the bottom half with a double and scored on a sacrifice fly by Scott Moore.
With first lady Michelle Obama watching in a private box at Camden Yards, Luke Scott, Ty Wigginton and Adam Jones hit successive homers off Matt Garza in the second inning. Scott homered again off Garza in the third to make it 4-1, but the Rays scored the game's next seven runs.
Obama was long gone by the time the Orioles launched a comeback that would force extra innings. Miguel Tejada fueled the charge with a two-run double in the seventh and a two-run double off Rafael Soriano that tied it in the ninth.
Baltimore last homered in three straight at-bats on Sept. 5, 1995 – a night made memorable by Cal Ripken Jr. tying Lou Gehrig's record of playing in 2,130 consecutive games.
Jeff Manto, Mark Smith and Brady Anderson connecting in succession against the California Angels was much less significant that Ripken's accomplishment, yet it turned out to be a feat that took the Orioles 15 years to duplicate.
After Scott hit a fastball over the 25-foot scoreboard in right field leading off the second, Wigginton went deep to left on a 1-1 pitch. Jones then drove a 2-2 slider into the seats in left.
They were Baltimore's first home runs in five games since the All-Star break.
Down 4-2, the Rays broke on top with a four-run sixth. A wild pitch by Jake Arrieta allowed one run to score and another came home on a throwing error by Wigginton, who made a diving stop of a smash to first by Aybar but threw wildly to second base seeking a force out.
John Jaso followed with a soft single to center, and Aybar added a two-run single in the seventh to make it 8-4.
Tejada doubled in two runs and scored on a single by Scott in the bottom half, but Brignac homered off David Hernandez in the eighth for a two-run lead.
Garza allowed seven runs and 10 hits in 6 1-3 innings in a rare ineffective performance against the Orioles. He remains 8-1 lifetime against Baltimore, including 5-0 at Camden Yards.
Rays All-Star outfielder Carl Crawford left in the first inning after being struck in the groin with a pickoff throw by Arrieta. After the ball hit him, Crawford rolled off first base and was tagged out. He remained doubled over in pain for several minutes before walking off the field with help from trainer Ron Porterfield.
Obama was in Baltimore to announce the partnership between the White House and Major League Baseball to battle childhood obesity. She took part in the first-pitch ceremony, but did not throw the ball. … Brian Anderson, who gave up those three successive homers in 1995, was in the TV booth Tuesday as a member of Tampa Bay's broadcast team. … The four homers allowed by Garza tied a career high.