The top-seeded American wasted three set points in the first and then faced a match point on her serve when trailing 6-5 in the second, but managed to hold on despite her game being littered with unforced errors.
Williams looked set to close out the match when she broke serve to go 5-2 up, but squandered the lead and then trailed 4-0 in the decisive tiebreaker before sealing the win in 3 hours, 26 minutes. It was the longest match Williams has ever played, according to the WTA Tour.
"I definitely feel really proud because I definitely wasn't playing my best tennis and I was far off playing well," Williams said. "Also, at that point I wasn't going to lose. After three hours, I'd better win."
Williams left the court for treatment when 3-2 up in the third set and returned with a strapped right thigh. She said she did not yet know how serious her leg injury was.
Her sister Venus had an easier time in beating Vera Zvonareva of Russia 7-5, 6-3, while second-seeded Caroline Wozniacki won her first-round match against Petra Kvitova of the Czech Republic 6-4, 6-2.
However, defending champion Dinara Safina was upset by Czech qualifier Klara Zakopalova in the first round, losing 7-6 (1), 7-6 (3).
After Zakopalova dominated the first tiebreaker, Safina found some momentum in the second set, winning three games in a row to take a 6-5 lead. However, the Russian rarely looked like the player that enjoyed a 16-match winning streak on clay last year and the 88th-ranked Zakopalova kept her calm to close out the match.
In another second-round match, Francesca Schiavone beat Sybille Bammer 6-2, 6-1.
In first-round action, Peng Shuai advanced when 10th-seeded Victoria Azarenka while trailing 3-0. Anabel Medina Garrigues, eighth-seeded Samantha Stosur, 14th-seeded Flavia Pennetta, 16th-seeded Nadia Petrova, Alisa Kleybanova and Patty Schnyder also won.
In the men's first round, qualifier Oleksandr Dolgopolov Jr. of Ukraine beat Italy's Andrea Seppi 6-3, 6-4 and will meet Rafael Nadal in the second round. Austria's Jurgen Melzer beat South African qualifier Kevin Anderson 6-2, 2-6, 6-4 to set up a meeting with either David Nalbandian or Tomas Berdych.
Spain's Feliciano Lopez eased past Lukasz Kubot of Poland 6-3, 6-3 and will face fifth-seeded Andy Roddick in the next round.
"Playing against someone as good as Roddick is going to be very nice," Lopez said. "I've never played against him on clay, and it's a new challenge that I'm thrilled about." Twelfth-seeded Gael Monfils of France beat compatriot Stephane Robert 6-2, 7-5.