The teams combined for 26 hits, but managed only two runs after the third inning.
After Scott Podsednik grounded out to open the 13th, Ramirez singled to right. Pierzynski then hit the first offering from Gonzalez to center and Ramirez raced all the way around from first to score the winning run.
The White Sox, in third place in the American League Central, moved within 6 1/2 games of division-leading Detroit.
The win went to Octavio Dotel (3-3), who worked the final three innings.