Williams, the 23-time grand slam winner and last year's runner-up, found herself staring down the barrel of a major upset against her fellow American.
McNally, standing up to Williams' second serve, had the 37-year-old on the ropes when she took the first set.
But Williams dug deep in a dramatic late-night session in New York to win 5-7, 6-3, 6-1 and progress to the third round.
"I think she really came out and played well, she showed no fear, she had nothing to lose and she played like it," said a relieved Williams.
"It's refreshing, and it's a different game. I don't get to play players like that too often.
"I knew I could get better, I tried to let Serena come through a little bit. In the first set she was picking out my wide serve, but I have two other serves so I tried them.
"I survived tonight. I'm not too pleased with the way I played at all. Serena you made way too many errors. But I'm still alive and I'll do better, I promise."
Serving to stay in the match, the 39-year-old showed her never-say-die spirit remains undimmed in a marathon penultimate game.
She forced Svitolina to serve for the match, the Ukrainian fifth seed eventually crossing the line for a 6-4, 6-4 victory.
"It was a really incredible match," said Svitolina.
"It was really special. It's unbelievable what Venus does, on and off the court she is a big inspiration.
"I had to stay very focused and try to put an extra ball over the net. She knows how to handle moments like this, it was incredibly tough and only a few points decided the match."
Third seed Karolina Pliskova is also through to the third round, the 27-year-old from the Czech Republic beating Georgia's Mariam Bolkvadze 6-1, 6-4.
Second seed Ashleigh Barty beat Lauren Davis of America 6-2, 7-6 (2) and 10th seed Madison Keys saw off China's Zhu Lin 6-4, 6-1.
Join our new commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies