The Swiss third seed, a five-time champion in New York, produced 19 unforced errors to surprisingly drop the first set against a player without a tour-level win.
But the 38-year-old bounced back to clinch his 1,224th career victory and book a meeting with Bosnia's Damir Dzumhur.