It was the 30-year-old American's first ever exit at the opening round stage of her 47-event Grand Slam career and her earliest loss at a major since she was knocked out of the Australian Open second round by sister Venus in 1998.
On a night of unbearable tension on Philippe Chatrier Court, Williams saved seven match points in the ninth game of the nerve-jangling decider.
"I'm disappointed, but that's life, things could be worse," said 13-time Grand Slam winner Williams, who missed last year's Roland Garros as she battled life-threatening blood clots in her lungs.
"I've been through so much in my life. I'm not sitting here happy. I've gotta figure out what I did wrong and not do it again. I fought until the end."
Williams came into the tournament with a 46-0 career record in Grand Slam first rounds and on a 17-0 winning streak on clay in 2012 with titles in Charleston and Madrid.
The 2002 champion was amongst the favourites for the title here.
Razzano was overjoyed by her astonishing triumph.
"You (the crowd) gave me your energy. I'm gonna have to rest. Thank you all for your support," said a breathless Razzano after a three-hour struggle.
"I knew I had it in me and I dug deep inside myself to find it."
Williams, the 2002 champion, had had the late evening match in her hands when she led by a set and 5/1 in the second set tiebreak as she looked set for a routine win.
But Razzano, the darling of the Paris crowd after playing the 2011 French Open just five days after the death of her fiance from a brain tumour, then reeled off the next six points of the breaker to level the tie.
Amidst rising tension and emotion, Williams appeared to cry as she sat in her courtside chair ahead of the final set.
She then fell to pieces on the court, slipping two breaks down to trail 4-0.
Williams then had to regather herself when umpire Eva Asderaki, with whom she had angrily clashed during her 2011 US Open final defeat against Samantha Stosur in New York last year, ordered the first point of the fifth game to be replayed.
Razzano served an ace to lead 5-0, but the drama did not end there.
Williams clawed her way back to 3-5 and had a break point when Asderaki punished Razzano for hindrance for a third time for letting out a loud yelp.
She saved it and went to match point which she squandered on an eighth double fault.
A second break point, as the French girl cramped, was saved before another match point quickly followed, this time wasted through a nerve-wracked wild forehand.
Razzano saved another break point and another, before a third match point was lost, sailing away on a wild, long forehand and then a fourth, this time as a backhand flew way beyond the baseline.
Williams saved a fifth match point with a sweeping, brutal forehand and then a sixth when Razzano pushed a backhand wide.
A fifth break point went begging for the American before a seventh match point arrived for the French girl, saved on this occasion by a pinpoint Williams drive which landed just on the line.
But on the eighth match point, Williams went long and Razzano celebrated an epic win after three hours and three minutes of action.
Razzano will face Dutchwoman Arantxa Rus for a place in the last 32.