With the game tied at 1, Murphy hit a home run to the right-centerfield bullpen off Masahiro Tanaka in the sixth inning to give the Mets a 2-1 lead.
Lucas Duda homered in the second inning and Juan Uribe hit a two-run pinch-hit home run for the Mets (84-63), who narrowed their magic number to eight games.
Jeurys Familia struck out Chase Headley with the bases loaded to end the game after Steven Matz pitched six innings of one-run ball.
Matz (4-0) struck out four batters and allowed seven hits and one walk, settling down after throwing 62 pitches through the first three innings.
Tanaka (12-7) allowed five hits and two runs in six innings for the Yankees (80-66), who fell 4 1/2 games back of the Toronto Blue Jays in the AL East.
After the Yankees took a 1-0 lead on Chris Young's first-inning sac fly, Duda hit a solo home run off Tanaka in the second inning to tie the game at 1.
In the seventh inning, Uribe hit a two-run home run to right field off Chasen Shreve to give the Mets a 4-1 lead.
Murphy hit a one-out triple in the eighth inning and pinch runner Eric Young Jr. scored on James Pazos' wild pitch to make it 5-1.
Noah Syndergaard (8-6, 3.20 ERA) will face Michael Pineda (10-8, 4.25 ERA) in the second game of the series Saturday at 1:05 p.m.