Biggest upset of the Rio Olympics
Defeat for the 34-year-old American robbed her of the chance to secure a fifth gold medal and her 2016 Games are now over after she and sister Venus were deposed as doubles champions in the first round.
Svitolina, 21, will face two-time Wimbledon champion Petra Kvitova for a place in the semi-finals.
Wimbledon champion Williams was clearly hampered by the shoulder injury which forced her to skip the Montreal event.
At one point, she screamed in pain, "shoulder, shoulder".
She even served up five double faults in the seventh game of the second set as she suffered her earliest ever loss at an Olympic singles event.
"Obviously I am very disappointed. The better player won but I can't wait for next time. That will be a really good match and I look forward to it," said Williams.
"It was a great opportunity. It didn't work out the way I wanted it to, but at least I was able to make it to Rio. That was one of my goals.
"It was awesome and fun, but it's over now."
Williams, who held a 4-0 record over Svitolina going into Tuesday's tie, committed error after error.
The 21-year-old Ukrainian -- coached on the tour by one of Williams' former rivals, Justine Henin -- broke for 5-4 in the opener and sealed it with an ace in the 10th game.
She was a break to the good again in the second set, nervelessly backing it up with a service hold for 3-1.
Williams briefly rallied to break back at 3-3 but her calamitous seventh game sealed her fate.
"I didn't really think about my record against Serena," said Svitolina.
"I didn't expect that I could win and I said don't think she will make a mistake. Just fight and focus.
"I stayed in the moment, relaxed and went for my shots especially in second set because it was really tight."
Svitolina said she was not surprised by Williams' uncharacteristic serving up of five double faults.
"She can also hit four aces in a row, so I expected the unexpected.
"I tried not to think about playing Serena, the Olympic champion and so many Grand Slams.
"I also thought she may be injured but I tried not to think about it too much."
Williams' defeat followed a first round loss for men's world number one Novak Djokovic.
It also blew the women's singles wide open with just two top 10 seeds making it to the quarter-finals.