The world number 176 made a blistering start as Nishikori blew four break points to find himself 5-2 down in the first set, and Majchrzak held his nerve to see out the first set.
Nishikori faced three break points in the opening game of the second, but he managed to hold in what he hoped would prove a pivotal moment in the contest.
In his first-ever Grand Slam main draw match, the 22-year-old showed no fear and it was Nishikori whose unforced error count mounted in the seventh game as a wayward backhand allowed the qualifier to take the first break.
Unlucky Majchrzak retires with cramp after going two sets up against Nishikori
Nishikori claimed his first title since 2016 when he downed Russia's Daniil Medvedev in Brisbane title earlier this month, but having rallied to have a set point, he lost the eventual tie break to leave himself with a mountain to climb.
Disaster struck for Majchrzak as he returned for the third set suffering from severe cramp. Despite a valiant effort to play though the pain, he was eventually forced to retire with his much-fancied opponent having fought back.
"I was trying to play but he was playing amazing tennis. I have to be happy that I didn't lose today," said a relieved Nishikori, who faces Ivo Karlovic in the next round.
Karlovic recovered from losing the opening set to defeat Poland's Hubert Hurkacz 6-7(5) 7-6(5) 7-6(3) 7-6(5) in an absorbing contest.
There was a shock as the seeded Marco Cecchinetto, of Italy, fell in five sets to Serbia's Filip Krajinovic, 4-6, 0-6, 6-1, 7-6(8), 6-4.
The number 11th seed Borna Coric overcame Belgium's Steve Darcis in straight sets, winning 6-1 6-4 6-4, and the Croatian will face Marton Fucsovics of Hungary next.
Meanwhile, Daniil Medvedev progressed in straight sets after the 15th-seeded Russian thrashed Lloyd Harris 6-1 6-2 6-1.
Fabio Fognini joins Medvedev in round two after the Italian 12th seed triumphed over Spain’s Jaume Munar, who retired with cramp when two sets down.
Ryan Harrison (USA) bt Jiri Vesely (CZE) 6-0, 7-5, 6-3