Third seed and Wimbledon winner Murray battled past world number 81 Mayer, who has never defeated a top-10 opponent, 7-5, 6-1, 3-6, 6-1 and goes on to tackle Germany’s Florian Mayer for a last-16 spot.
Murray fired 28 winners while the Argentine hit 49 unforced errors.
“It was a very tough match,” Murray said of an opponent who like him was born on May 15, 1987.
“Both of us ran a lot and it was very humid. I’m just glad I was able to put it together and pull it out in the fourth set.”
World number one Djokovic survived a first-set wobble before racing away with 12 of the last 14 games to defeat Germany’s Benjamin Becker 7-6 (7/2), 6-2, 6-2 after saving two set points in the 10th game of the opener.
Djokovic, the 2011 champion who is bidding to reach the final for a fourth successive year, sent down 13 aces and 40 winners against the 32-year-old Becker, who ended Andre Agassi’s career in the American’s last match in New York in 2006.
“Becker is a quality player and he should have won the first set. I was fortunate to come out of it, but after that I felt more comfortable on the court,” said Djokovic, who next plays Portugal’s Joao Sousa.
Dangerous Czech fifth seed Tomas Berdych, who defeated Roger Federer on his way to the semi-finals last year, made the third round by seeing off America’s Denis Kudla 7-6 (7/3), 7-6 (7/3), 6-3.
He next meets French 31st seed Julien Benneteau, who eased past compatriot Jeremy Chardy 6-4, 6-3, 6-4.
In the women’s event, Chinese fifth seed Li Na and third-seeded Pole Agnieszka Radwanska made the last 16.
Li hit 11 aces in a 6-2, 7-5 victory against teenager Laura Robson, avenging her loss to the Briton at the same stage last year.
The 31-year-old Li, who saw her opponent hit 30 unforced errors, goes on to face Serbian ninth seed Jelena Jankovic, the 2008 runner-up, for a quarter-final spot.
“I was really happy how I was hitting on the court,” Li said. “And I thought I served really well.”
Li’s best US Open performance was a run to the quarter-finals in 2009, one round better than Radwanska, who has stumbled at the fourth-round stage on three occasions.
The 2012 Wimbledon runner-up made the last 16 once again with a 6-4, 7-6 (7/1) win over Russian 32nd seed Anastasia Pavlyuchenkova, a quarter-finalist in 2011.
Pavlyuchenkova, seeded at a major for the first time, was undone by 41 unforced errors, which rendered her 32 winners irrelevant against the steady Radwanska, who now faces Ekaterina Makarova.
Russian 24th seed Makarova clinched a 6-4, 7-5 win over German 16th seed Sabine Lisicki, who had wowed Wimbledon last month when she defeated Serena Williams on her way to a final loss against Marion Bartoli.
Makarova, a 25-year-old left-hander, was a quarter-finalist at the Australian Open this year.
Later Friday, four-time women’s champion Williams, the top seed, who has dropped just four games in her opening two matches, takes on Russian-born Kazkhastan player Yaroslava Shvedova, the world number 78, for a last-16 spot.
Williams, chasing a 17th Grand Slam title, has won both their previous meetings, at Toronto in 2009 and Wimbledon last year.
Shvedova has twice been a women’s doubles champion at the US Open, partnering Vania King to victory in 2010 and 2011.
Friday’s action also sees two former men’s champions clash for a place in the third round when Australia’s 2001 winner Lleyton Hewitt meets Argentina’s Juan Martin Del Potro, the sixth seed who claimed the 2009 title.