Wozniacki took a medical timeout while trailing 3-4 in the third, getting her left knee taped before playing on.
Second seed Wozniacki held her nerve in a tight final set featuring seven breaks of serve.
The dogged retriever and shotmaker got back to level-pegging in the third for 4-all, then held serve before breaking Halep for a final time in the epic, with the Romanian putting a backhand into the net on first match point.
"My voice is shaking, it's a very emotional moment," Wozniacki said. "It's been an incredible two weeks. It was a tough day for Simona -- I'm sorry I had to win today. We had an incredible match, an incredible fight. Again, I'm sorry."
Wozniacki finished the match, which lasted for almost three hours, with 49 winners and 28 unforced errors, breaking on five of 14 chances. Halep went 5 for 12 on break points.
"I can still smile," Halep said. "I cried, but now I'm smiling. I'm sad. But it's just a tennis match. She was better."
Halep said she was suffering physically.
"My right foot is swollen, both of my feet are dead," Halep said. "I was hurting and could not train for more than 10-15 minutes per day. I'll get a scan on both feet. Today my legs were not fast enough. She was running well and responding well."
The two-time Roland Garros runner-up added: "I did 100 percent what I could today. That's why I can say that I'm not sad for that.I'm sad that I lost the match, I was not the winner. But life goes on.
"For sure in the future, if I keep working like this and I keep playing like this, I will be in a good position again."
Wozniacki has forever shed the label of No. 1 without a Grand Slam title after her victory.
(c)2018 Deutsche Presse-Agentur GmbH (Hamburg, Germany)
Visit Deutsche Presse-Agentur GmbH (Hamburg, Germany) at www.dpa.de/English.82.0.html
Distributed by Tribune Content Agency, LLC.