Yoenis Cespedes and Josh Donaldson each had two hits for the A's. Oakland has won four of five and is a season-high 16 games over .500 at 44-28.
Gray (7-3) had won just two of his previous eight starts before going seven innings and striking out seven.
Luke Gregerson pitched the eighth while Sean Doolittle worked the ninth for his ninth save.
Nick Tepesch (2-3) went five innings.
Shin-Soo Choo drove in both runs for the Rangers.
A's manager Bob Melvin shuffled his lineup and didn't start center fielder Coco Crisp and second baseman Eric Sogard.
Oakland's offense didn't miss a beat.
John Jaso replaced Crisp in the leadoff spot and knocked in the A's first run with a double in the third. Craig Gentry, who filled in at center field, added two hits and scored a run, while Alberto Callaspo also had two hits while playing second.
That was enough for Gray, who gave up two runs and six hits. He improved to 8-2 in 13 career starts against teams from within the A's division.
Gray bounced back nicely from his recent rough stretch. The right-hander needed only 31 pitches to get through the first three innings, then struck out Brad Snyder on a high 95 mph fastball to end the fourth with runners at second and third.
Gray also got some help from left fielder Cespedes, who made a leaping catch at the warning track to rob Adrian Beltre of extra bases two batters before Snyder struck out.
Gray's lone mistake came in the fifth when Texas loaded the bases with two outs. He walked two and gave up an infield single before Choo's two-run single made it 2-all.
Cespedes scored the go-ahead run in the bottom of the inning. He singled off Tepesch and scored on Moss' double to right, barely beating the throw home with a headfirst slide.
After Donaldson singled Moss to third, Stephen Vogt hit a short sacrifice fly to left to put Oakland up 4-2.
Tepesch remained winless since May 26. He allowed nine hits over five innings with two walks and one strikeout.
NOTES: Doolittle has not allowed a run in 22 1/3 innings, the longest active streak in the AL. ... Crisp was given a normal day off. ... Sogard pinch-ran after Callaspo singled in the ninth. ... Texas LHP Joe Saunders (0-2) pitches the opener against the Angels and has allowed two earned runs or fewer in four starts since coming off the DL. ... LHP Scott Kazmir (8-2) opens against Boston and has a 0.95 ERA over his previous four starts.