Gray (3-3) picked up his first win since May 24. Rosales and Joyce broke it open with their drives against David Robertson and Chris Beck to start the ninth, and Oakland completed the three-game sweep after getting dominated by Derek Holland.
The White Sox were sailing along with a 2-0 lead after Adam Engel hit his first career homer and Jose Abreu doubled and scored.
Oakland pulled within one on pinch-hitter Jed Lowrie's RBI double in the seventh. The Athletics went ahead in the eighth on RBI singles by Khris Davis and Yonder Alonso against Tommy Kahnle (0-2) and Robertson.
Santiago Casilla gave up a leadoff homer to Melky Cabrera in the ninth but earned his 13th save in 16 chances.