MADRID, Spain - No.2 seed Caroline Wozniacki kept her bid to reclaim the World No.1 ranking alive with a thrilling second round comeback in Madrid on Monday, defeating Ashleigh Barty, 6-2, 4-6, 6-4.

The Australian Open champion found herself on the brink of defeat against the unseeded Australian No.1 as she trailed 4-2 in the final set, but ran off the last four games to stay in the tournament after a two hour and five minute battle. 

"She played extremely well, I thought. She wasn't making any errors at one point. I think it kind of turned around when I got that net cord. It went over, and instead of being 5-2 for her in the third, I still had a chance to kind of survive," Wozniacki said after the match, referencing a moment in the seventh game of the decider which helped her break serve.

"I think that's where it changed a little bit. I just kind of stayed in it, and then I served pretty well to close it off."

After leading by a set and a break at 6-2, 4-3, Wozniacki found herself in a dramatic tussle against the World No.18, who won three straight games to snatch the second set, and eventually led 4-2 in the decider herself.

However, Wozniacki stood tall in the late stages as Barty started to misfire off the ground, with the Australian ultimately accumulating 54 unforced errors for the match.

The Dane's defenses at the baseline withstood 38 winners from Barty's racquet over the course of the match, and Wozniacki also successfully saved eight of the 11 break points she faced -- perhaps none bigger than the two opportuntities that Barty held in the eighth game of the final set which would've seen her serve for the match.

"I think there's a lot of positives to take with me. I thought we played pretty well. The first set I won 6-2, but I made most of my shots. I got the important ones, as well. Even when I was down Love-40, I still managed to come back," the Australian Open champion added.

"In the second set, the only negative I can say I think I didn't play my best game when I was up 4-3 and serving. I made a double-fault. She also played a really good game, so... I wish I could have just gotten it right then and there.

"I think there's a lot of positives to take with me. I thought she played really well. I think I played well, served well. I moved pretty well. I have to say I think there's a lot of big things coming from her. I think we will see a lot of her in the future, as well."

The World No.2 served at a stellar 71 percent for the duration of the encounter, and though Barty won an identical percentage of her own first serve points in the match when she landed it, Wozniacki won 26 of 37 points played when the Australian struck a second serve.

Wozniacki will next face Volvo Car Open champion and former French Open semifinalist Kiki Bertens, who added another notable scalp to her name this clay court season with a 6-1, 6-4 victory over No.15 seed Anastasija Sevastova.

"It'll be another tough match. She's a big server with a big forehand. She loves the clay. I haven't had an easy draw here, but I don't think anyone has. It's just about going for it again. That's all I can do, is go out there and do my best," Wozniacki said.

"I think it's definitely a surface that I think evens out a lot of the playing field. I think there's more people that has an opportunity here on this surface.

"I played a finals on clay last year. I think I played Stuttgart finals a few years back. There was one year I didn't play on clay at all. It's just I think part of the progress. I actually don't mind it. It's not my favorite surface, but I think I can play well on it. It's just all about getting the mental attitude right. I think I have that. Then you just kind of take it from there."