Williams was down a set and a break before she started hitting the lines. She needed 2 hours 41 minutes to win.
"I was making a lot of unforced errors in general," Williams said. "But I just thought: `Just keep fighting. Hopefully I can just hold on and hold on, try to break, keep going for each shot.'
"I just never wanted to stop."
There were five service breaks in the third set. Williams clinched victory with the last one on her third match point.
"Especially when you play someone like Caroline or other opponents, you know your match might be a little longer than normal," Williams said. "You go in there thinking: `This is not going to be routine.' You're ready."
Williams is now 7-1 against Wozniacki.
She could face her sister in the semifinals. Venus Williams plays Carla Suarez Navarro later Friday.
Wozniacki, coming off a win at Istanbul, had won eight matches in a row. She broke for a 3-2 lead in the first set and fought off two break points to close the set.