His final match as manager ended in a 2-0 win at home to Wolves
Third seeded Spaniard Muguruza, who has struggled in the aftermath of her Roland Garros breakthrough in June, slumped to a 7-5, 6-4 loss to Latvia's Anastasija Sevastova, the world number 48.
A horribly out of sorts Muguruza rallied from 1-5 down in the second set, saving three match points, but Sevastova, who briefly quit the sport in 2013, held her nerve for the victory.
Having not won a match at the US Open in five years before this week, 26-year-old Sevastova now goes on to face Kateryna Bondarenko, a 5-7, 7-6 (7/5), 7-5 winner in three hours over China's Zheng Saisai.
"This is why I came back to the sport for the big stages like this and night sessions at the Slams. But I was shaking a little at the end," she said.
Muguruza admitted she had been outplayed.
"It was a very tough match. I think I didn't play well. Everything she was doing was working," said the 22-year-old who has never made the third round in New York.
Meanwhile, 120th-ranked Ryan Harrison of the United States stunned fifth seeded Raonic 6-7 (4/7), 7-5, 7-5, 6-1 in another second round upset.
"It was extremely physical out there. I was playing on adrenaline," said 24-year-old qualifier Harrison who was as high as 43 in the world in 2012.
He goes on to face experienced Cypriot Marcos Baghdatis for a place in the last 16.
Harrison has now reached the third round of a Slam for the first time after recording just a second win over a top 10 opponent in 27 meetings.
Raonic, considered as a potential title dangerman in New York, hit 69 winners but committed 62 unforced errors.
"I started cramping midway through the second set. There was a lot of nerves and stress. It was a result of over-exuberance," said 25-year-old Raonic.
Rafael Nadal, the 2010 and 2013 champion, eased past Italy's Andreas Seppi 6-0, 7-5, 6-1 in a match which became the first to be completed under the new retractable roof on Ashe.
Light rain caused the structure to be closed at 3-3 in the second set with play only held up for around seven minutes.
"It's part of history and I am very happy to be the first to play under the roof," said Nadal, who was also the first to practice beneath the roof on the cavernous 22,000-capacity arena.
Nadal beat Seppi for the eighth time in nine matches and next faces Russia's Andrey Kuznetsov.
World number one Novak Djokovic made the last 32 of a major for the 33rd successive time without hitting a ball when Jiri Vesely of the Czech Republic withdrew from their second round encounter suffering an inflammation of the left forearm.
Djokovic will face 34-year-old Russian Mikhail Youzhny, twice a semi-finalist, on Friday for a place in the last 16.
Britain's Johanna Konta, the 13th seed, collapsed on court with heat sickness before completing a 6-2, 5-7, 6-2 win over Bulgaria's Tsvetana Pironkova.
After a medical timeout, the Briton dropped the second set before heading off on a lengthy toilet break which did little to help her opponent's composure in the decider.
"I'm a little embarrassed. I'm not a fan of drama. I did the best that I could with the cards that I had," said Konta.
Angelique Kerber, the second seeded Australian Open champion, made the last 32 by seeing off 34-year-old Mirjana Lucic-Baroni of Croatia 6-2, 7-6 (9/7).
Kerber faces 17-year-old CiCi Bellis of the United States, for a place in the last 16.
Croatian seventh seed Marin Cilic, the 2014 champion, made the last 32 by seeing off Sergiy Stakhovsky 6-1, 6-2, 6-3.
His final match as manager ended in a 2-0 win at home to Wolves
The Abu Dhabi-owned City won an unprecedented fourth straight English top flight title with a 3-1 win over West Ham United
Iranian rescue teams are scouring a fog-shrouded mountainside after an accident happened to the helicopter transporting Iranian president
Chasing 215 for victory against Punjab, Hyderabad reached the target with five balls to spare at their home
The Copernicus Emergency Management Service provides mapping products based on satellite imagery
City beat West Ham 3-1 to become the first team to win four straight Premier League titles
Dubai Crown Prince reviews strategic plans for the development and launch of satellites under the UAE Satellite Programme
Combs is the target of several civil lawsuits that characterise him as a violent sexual predator who used alcohol and drugs to subdue his victims