Swiatek dropped serve in the opening game at the Foro Italico but rattled off the next six to seize control against the 63rd-ranked American.
The Pole seemed on course for a routine victory when she pulled 4-2 in front in the second set, but McNally twice broke Swiatek as the Pole served for the match and then snatched the tie-break.
Swiatek again nudged ahead with a break for a 3-1 lead in the decider. McNally clawed herself level at 3-all before Swiatek took the final three games to book her place in the next round, to her visible relief.
"It was a tough match, Caty really played great," said Swiatek.
"I had to be patient. For sure, some mistakes happened. It was not an easy match. I'm really happy I was solid at the end and in the important moments. I kept it together."
Swiatek will play the US 28th seed Emma Navarro or Italy's Elisabetta Cocciaretto this weekend for a place in the last 16.
The Pole suffered her earliest exit in five appearances in Madrid last month when she retired in the third round due to a viral illness. She was knocked out at the same stage in Rome last year as the defending champion.
Swiatek, a six-time Grand Slam champion, has not won a clay tournament since capturing the last of her four French Open titles in 2024.
Alexandra Eala of the Philippines advanced with a 6-4, 6-3 win over the Chinese 31st seed Wang Xinyu.
Canadian 10th seed Victoria Mboko withdrew from the event on Friday due to illness. She will be replaced in the draw by Czech lucky loser Nikola Bartunkova.
Novak Djokovic is set for his first appearance on clay this season when he plays 20-year-old Croatian qualifier Dino Prizmic.
The 38-year-old Djokovic has not played since losing in the last 16 at Indian Wells in March. He pulled out of tournaments in Miami, Monte Carlo and Madrid while recovering from a shoulder injury.
