There was also misery for defending champion Vera Zvonareva who quit with a hip injury midway through her second round match against Romania’s Monica Niculescu.
Czech left-hander Safarova saved three match points in the third set and played a superb tiebreaker to set up a third round clash with Russian Svetlana Kuznetsova, who defeated compatriot Maria Kirilenko 6-4, 6-4.
Wozniacki, seeded two but now ranked at four in the world, was deposed from the world top spot when she was knocked out of the Australian Open quarter-finals.
"I just want to get out of here (the press conference room). You don’t want to stay when you lose a match like that," Wozniacki.
"It’s really disappointing but you have to move on," added the Dane, who was runner up twice in Doha -- in the 2010 season-ending championships and last year’s Qatar Open.
There were no such problems, however, for newly-crowned world number one and Australian Open champion Victoria Azarenka who cruised into the third round, beating Germany’s Mona Barthel 6-1, 6-0.
The Belarussian top seed will now take on Romania’s Simona Halep.
Safarova, who is now 2-1 in career clashes with Wozniacki, said: "Unless you win the final point, the match is not over."
"I just wanted to keep fighting. It feels absolutely amazing," added the 25-year-old, who has won four titles on the WTA Tour.
Even the presence of golfer boyfriend Rory McIlroy couldn’t inspire Wozniacki as she made several unforced errors on big points to allow Safarova back into the match in the second set.
The Dane also failed to take advantage of three match points in the 10th game of the third.
Buoyed by the let-off, Safarova really turned it on in the tiebreaker, pulling away after the scores were tied 3-3, a lucky net cord giving her a 4-3 lead.
A cracking double-handed backhand passing shot saw the Czech go up 5-3.
Earlier Zvonareva’s hip problem came back to haunt her for the second consecutive week when she called it quits after trailing Niculescu.
Niculescu had taken the first set 7-5 and was leading 3-2 in the second when Zvonareva, the sixth seed, decided she couldn’t take the pain anymore.
Last week in Pattaya, Zvonareva quit during her quarter-final match with another Romanian, Sorana Cirstea, who was taking on Australia's Samantha Stosur in Doha later on Wednesday.
Earlier, fourth-seeded Agnieszka Radwanska of Poland thrashed Great Britain's Anne Keothavong 6-1, 6-2, while French fifth seed Marion Bartoli also had it easy, beating Spaniard Anabel Medina Garrigues 6-2, 6-0.
Serb eighth seed Jelena Jankovic fell to Israeli Shahar Peer 7-6 (7/4), 6-2 while compatriot Ana Ivanovic also bowed out, losing to 6-4, 6-4 to the Czech Republic's Petra Cetkovska.
US Open champion Samantha Stosur of Australia advanced beating Romania's Sorana Cirstea 6-4, 7-6 (7/4)
What the stars mean:
★ Poor ★ ★ Promising ★★★ Good ★★★★ Very good ★★★★★ Exceptional