Canadian Shapovalov pulled off one of the biggest victories of his career to beat third seed Alexander Zverev in the fourth round to reach his third slam quarter-final and first in Melbourne.
But the 22-year-old was unable to find his best form in the opening set against the Spaniard, though, and then showed his frustration by getting into a row with umpire Carlos Bernardes over the time Nadal was taking between points.
After Bernardes refused to give Nadal a time violation for delaying Shapovalov on his serve, the Canadian shouted: "You guys are all corrupt," and he and Nadal then had words at the net.
It did not distract Nadal, who moved into a two-set lead, but Shapovalov began to turn the tide in the third set and clinched it with a backhand winner after his opponent was given a time violation.
Nadal began to look weary and troubled in the fourth set, leaving the court for six and a half minutes at the end of it for a medical examination and a toilet break.
Two double faults - he served 11 during the match - put him in trouble in the opening game of the decider but Shapovalov could not take advantage and then dropped serve himself to give Nadal a lifeline.
The Spaniard seized it, finding more conviction in his shots again and exploiting costly errors from his opponent, who will feel he had the match in his grasp.
When a final backhand volley drifted wide, Shapovalov smashed his racket angrily on the court while Nadal celebrated reaching his 36th grand slam semi-final.