Matt Joyce added two hits, Josh Harrison drove in two runs while Andrew McCutcheon doubled and scored on a wild pitch to help the Pirates to their first win in their history at the Coliseum and just their second in 13 games between the two franchises.
They did it by taking advantage of another shaky outing by Gray (3-7).
He gave up seven runs, hit a batter and threw two wild pitches in six innings while losing his sixth consecutive decision. The right-hander, third in the 2015 AL Cy Young voting, is winless since April 22.
Marcus Semien hit his 17th home run of the season for Oakland.
Pirates starter Jeff Locke (8-5) also struggled early but retired the final nine batters he faced to win his third straight. He gave up three runs over five innings with three walks and three strikeouts.
Three relievers combined to retire the final 12 batters and complete the four-hitter.
Mercer homered in the third and added an RBI single as part of a two-run fifth.
Harrison's two-out, two-run double in the sixth put the Pirates up 7-3.
Jed Lowrie had decent results while batting leadoff for the first time this season. He drew a walk from Locke in the first before Semien homered on a 3-2 pitch. Oakland's second baseman added an RBI double in the second to make it 3-0.
Pirates: Ryan Vogelsong faced hitters while throwing off the mound in the latest step of his recovery after getting hit in the face with a pitch on May 23. Vogelsong, who underwent surgery on June 2 to repair the multiple fractures he suffered, remains on the 60-day disabled list and isn't eligible to return until July 23. . Right-hander Gerrit Cole (triceps strain) also pitched a simulated game prior to the series opener with Oakland. The Pirates are encouraged but haven't determined what the next step is. . Francisco Cervelli (broken hamate in left hand) continues to make progress and could catch the next round of sim games for Vogelsgong and Cole.
Athletics: Infielder Tyler Ladendorf was recalled from Triple-A Nashville before the game. Left-hander Dillion Overton, the losing pitcher against San Francisco on Thursday, was optioned down. Overton went 1-1 with an 11.42 ERA in two starts.
Athletics: Rich Hill is expected to come off the disabled list to start against Pittsburgh. The right-hander had been out since May 30 with a strained groin.