Todd Frazier and Jeff McNeil each homered twice, helping the surging Mets stun Diamondbacks ace Robbie Ray and beat Arizona, 9-0, on Wednesday night.

The Mets (75-70) have won the first three games of a pivotal four-game series to move past the Diamondbacks (75-71) in the race for the second National League wild card. The Mets entered Wednesday three games behind the Chicago Cubs, who played later Wednesday in San Diego.

Arizona has lost four straight since going 11-1 to move into the crowded N.L. playoff picture.

Steven Matz (10-8) tossed six scoreless innings for the Mets, who jumped on Ray (12-8) for five runs before chasing him with two outs in the first. Wilson Ramos (groundout) and J.D. Davis (single) had an R.B.I. before Frazier and Brandon Nimmo homered on consecutive pitches.

Matz allowed four hits and three walks while striking out seven. He issued all three walks to open the second before striking Carson Kelly and inducing a double-play grounder from Kevin Cron.