Pearce and Adam Jones each had two hits and Jonathan Schoop drove in a run for the Orioles, who have won three straight and six of their last eight.
Ubaldo Jimenez (2-4) earned the win after surrendering just one run on seven hits with three strikeouts in 5 1/3 innings.
David Price (3-3) was tagged with the loss after allowing three runs on nine hits in five-plus innings.
The Rays took an early lead in the first. Desmond Jennings was safe on a force out and moved to third on Matt Joyce's flyout. Longoria's two-out, line- drive single plated Jennings.
J.J. Hardy got aboard with a two-out double in the second before Pearce belted a fastball over the left-field wall to give the O's a 2-1 lead.
Baltimore added another run in the fourth. Jones and Pearce were aboard with two outs before Schoop's single up the middle scored Jones.
Jimenez's outing ended in the sixth after Wil Myers and David DeJesus both singled with one out to put runners at the corners. Ryan Webb came on to face Escobar, who reached second on a fielder's choice, and Myers got caught in a rundown for the second out of the inning. Webb got out of the jam by getting Ryan Hanigan to ground out.
Darren O'Day came on to pitch the ninth for Baltimore, but Hanigan greeted him with a leadoff single. Ben Zobrist also singled before Jennings doubled into a double play. Matt Joyce grounded out to first as O'Day earned his second save of the season.