The Australian needed three match points before winning 6-1 7-5 on Arthur Ashe Stadium to pick up her 50th Grand Slam match victory.
The top seed raced through the first set but was unable to convert a match point at 5-3 in the second.
She was broken but responded to eventually serve out the match.
Barty will face American Shelby Rogers or Romanian Sorana Cirstea in the third round.