The White Sox looked to have a victory wrapped up in the top of the ninth when pinch-hitter Daniel Murphy lifted a routine pop fly near the pitcher's mound with two outs.
Third baseman Conor Gillaspie called for the catch, but second baseman Gordon Beckham came charging in, tripped over the mound and stumbled into Gillaspie, causing the ball to drop and allowing New York's David Wright to score the tying run.
But Chicago quickly regrouped in the next-half inning when Jeff Keppinger led off with a single and Mets pitcher LaTroy Hawkins (2-1) couldn't handle Beckham's sacrifice bunt, allowing him to reach on his error.
Keppinger went to third on a fielder's choice and after Alejandro De Aza popped out, Ramirez lined a hit down the left field line for the game winner, his second RBI of the contest.
Addison Reed (3-0) got the decision after starter Chris Sale had limited the Mets to three runs on four hits over eight innings.
Andrew Brown homered for New York, which dropped the first of a two game interleague series.
Ohio crash that killed two caught on camera [VIDEO]
Wisconsin business offering 'therapeutic cuddling' forced to close