Federer next faces another potential banana skin in Ukrainian qualifier Alexandr Dolgopolov on Thursday.
There were 24 places in the rankings between the Swiss legend and Schwartzman and a significant height difference — Federer towering over the 170cm (five foot, seven inch) Argentine.
But Schwartzman cut the 185cm Federer down to size and an error-strewn performance from the world number two was summed up when he squandered an easy backhand volley at the net to go to the first-set tie break.
Federer s Chinese fans, in red t-shirts and with their faces painted, were stunned.
But from 2-0 up in the tie break Schwartzman lost five points in a row and a relieved Federer clenched his fist when he finally prevailed in the set.
Unseeded Schwartzman began racking up the mistakes in the second set and Federer got an early break to put him into the next round.
Still Schwartzman refused to go quietly in the second set, before Federer went through 7-6, 6-4.
“Tough match, I knew going in it was not going to be easy,” said Federer, 36.
“He s had a great run in recent weeks and months, I really felt that he was confident, shaking off misses no problem.
“But I think I served well, I had good concentration, had good energy as well, which I think is always important early on in a tournament.”