WATCH the Madrid Open LIVE on beIN SPORTS | available via Foxtel, Kayo Sports, Fetch TV & beIN SPORTS CONNECT
The 2019 French Open champion defeated last year's winner at Roland Garros 7-5 6-4 to reach the quarter-finals in the Spanish capital.
Swiatek herself came into the contest having won 18 consecutive sets on clay and took early control of the contest as she went 3-0 up in the opener.
However, Barty recovered thanks to imperious play behind her serve as she won 80 per cent of all points behind her first delivery and avoided being broken for the remainder of the contest.
The world number one was 0-40 down at 3-2 in the second but rallied to hold before seeing out the win.
Barty will now face ninth seed Petra Kvitova in the last eight after she battled past Veronika Kudermetova 6-3 4-6 6-4.
The three-time Madrid Open champion required just over two hours to beat the Russian, who has won more matches in 2021 (22) than anyone except Barty (23).
"Always playing Ash, it's a great challenge," Kvitova said. "It will be a great match-up. I really will enjoy it. I'm really looking forward for it.
"She has a game for clay. She's sliding. She's playing lots of slice and everything... She likes clay a little bit more than me probably. I like Madrid. So, who knows, right?"
Eighth seed Belinda Bencic is also through after Ons Jabeur retired from their match with a thigh injury. She will now face Paula Badosa, who needed more than two and a half hours to defeat Anastasija Sevastova in three sets.
At the L'Open 35 de Saint-Malo, Alize Cornet suffered a surprise defeat in the first round as Oceane Dodin prevailed in a marathon match.
Dodin knocked out the top seed in two hours and 56 minutes, recovering after letting two match points slip in the second-set tie-break to win 7-5 6-7 (8-10) 6-1.
Third seed Alison van Uytvanck also made an early exit as Anna Karolina Schmiedlova came from a set down to prevail 2-6 7-5 6-3.
But Viktorija Golubic was victorious, the fifth seed winning in straight sets against Clara Burel.