The 14-time Grand Slam champion prevailed 6-2, 3-6, 6-7 (2/7), 6-3, 7-5 in 4hr 12min and will now play unseeded Israeli Dudi Sela in the third round.
Nadal looked to be suffering from stomach cramps during the match and called for the trainer and doctor early in the third set.
He took a tablet and continued on but at one changeover motioned to his player box that he was experiencing a stomach ailment. He was physically ill on the court.
"I tried to have my best attitude and always with the support of the fantastic crowd."
More From This Section
The Spanish great appeared to be making some headway when he broke Smyczek's serve to lead 5-3 only to give back the service break with a double-fault on break point.
The marathon 81-minute third set went to a tiebreaker which the American qualifier captured seven points to two.
The breakthrough came in the 11th game of the final set when Nadal broke Smyczek's serve and then wrapped up the victory on his fourth match point to his immense relief.
"It was a very tough night for me. I first want to congratulate Tim because he's a gentleman for what he did in the last game," Nadal said.
"Not many people would have done what he did at 6-5 in the fifth set after four hours."
Nadal said he suffered from stomach cramps after the first set.
His shaky condition showed when he committed an uncharacteristic 53 unforced errors and double-faulted three times on break points. He lost his serve five times.