The 6-foot-6 Querrey, seeded 28th, completed the 7-6 (6), 6-1, 3-6, 7-6 (5) third-round win in a match that carried over from Friday because of rain at the All England Club in London.
"It's incredible, especially here at Wimbledon, the biggest tournament in the world," Querrey, 28, said on the court after the match. "I'm so ecstatic."
Querrey, a California native, led the 29-year-old Serbian after taking the first two sets Friday when persistent rain postponed the match until Saturday.
When play resumed Saturday, Djokovic quickly took a 5-0 lead en route to winning the third set.
Djokovic then served for the fourth at 5-4, but he was broken by Querrey and they headed to a tiebreaker. The match closed on a forehand error by Djokovic.
"Congratulations to Sam. He played a terrific match," Djokovic said in his post-match press conference. "He serves very well, as he usually does. I think that part of his game was brutal today. He made a lot of free points with the first serve. Just well done. He just overpowered me."
Querrey endured three more rain delays Saturday to improve to 21-1 in his career when winning the first two sets. He finished the match with 31 aces.
"I'm really excited. It's an unbelievable win," Querrey said in a postmatch interview before heading off to play doubles. "To do it here at Wimbledon is really special. ... I served well the whole time, played a great tiebreaker at the end to get the win."
Djokovic hadn't lost at any major tournament in more than a year. He was beaten by Stan Wawrinka in the French Open final in June 2015. Since then, Djokovic won his third title at Wimbledon last July, his second at the U.S. Open in September, his sixth at the Australian Open in January and his first at the French Open less than a month ago.
Djokovic has the third-longest Grand Slam match streak at 30 in the history of men's tennis. The longest winning streak at majors for a man is 37 matches, set by Don Budge from 1937-38, followed by Rod Laver with 31. Djokovic was bidding for a 13th major championship overall.
Djokovic holds all four Grand Slam crowns at the same time and was attempting to join Budge as the second player in tennis history to win five straight majors. Budge won six successive titles between 1937 Wimbledon and the 1938 U.S. Championships.
"I believe in positive things in life," Djokovic said. "I managed to win four Grand Slams in a row two different seasons. I want to try to focus on that rather than on failure.
"I had my chances maybe in the fourth set, serving for the set. In the tiebreak, I was leading. Just wasn't feeling the ball as well as I wished. But that's sports.
"As I said, you know, in sports everything is possible. If you're playing somebody of as a high quality as Sam Querrey is on this surface with a big serve, anything can happen. I was a few points away from losing last year against Kevin Anderson in a very similar match on the same court. Sometimes it works in your favor, sometimes against. You got to deal with that."
Querrey will next face Frenchman Nicolas Mahut, who beat countryman and doubles partner Pierre-Hugues Herbert 7-6 (5), 6-4, 3-6, 6-3.
Querrey was joined in the fourth round by fellow American Steve Johnson, who beat Grigor Dimitrov of Bulgaria 6-7 (6), 7-6 (3), 6-4, 6-2 to reach the round of 16. Dimitrov will next play No. 3 Roger Federer.
No. 2 Andy Murray of Scotland made his way into the fourth round by beating John Millman of Australia 6-3, 7-5, 6-2.
Murray is now the odds-on favorite to win his second Wimbledon title.
"I need to reach the final for that (Djokovic) result to have any baring whatsoever on my performance at all," Murray told the BBC afterwards. "I have very, very tough guys left in my half of the draw, especially in the next round.
"Novak's run has been amazing. He almost found a way to get back into that one again today. What he's done over the last 12, 18 months, I don't think we'll see for a long, long time. It's unfortunate for him, but it's an amazing run he's been on. I think right now everyone expects Novak to win every match he plays. The level of consistency he's had has been amazing. It's normal in a way to have one match or two matches where you're not playing at your best, where your opponent plays a great match. I didn't see loads of it, but it's impossible to win every single match of every tournament."
In other men's action, fifth-seeded Kei Nishikori of Japan reached the fourth round to equal his best performance at the All England Club with a 7-5, 6-3, 7-5 win over Andrey Kuznetsov of Russia.
Nishokori will next face No. 9 seed Marin Cilic, who beat Lukas Lacko of Slovakia 6-3, 6-3, 6-4.
Other seeded players to advance included No. 11 David Goffin of Belguim, who beat Denis Istomin of Uzbekistan 6-4, 6-3, 2-6, 6-1, and No. 19 Bernard Tomic of Australia, who beat No. 14 Roberto Bautista Agut of Spain 6-2, 6-4, 6-4.
The second round was finally completed on Saturday, two days later than normal because of rain, with No. 24 seed Alexander Zverev of Germany beating Mikhail Youzhny of Russia 6-4, 3-6, 6-0, 4-6, 6-2.
On the women's side, American Madison Keys, the ninth seed, was taken to a third set by Alize Cornet of France before winning 6-4, 5-7, 6-2 and advancing to the fourth round.
American Sloane Stephens, seeded No. 18, completed her match against Mandy Minella of Luxembourg 3-6, 7-6 (6), 8-6 to advance to the third round.
Stephens saved a match point in the second-set tiebreaker Friday, but the match was then suspended by rain with the score tied at 3-3 in the third set.
Kvitova and Makarova started the match Friday, but rain suspended play. After several delays Saturday, Makarova was finally able to close out the match and the second round.
Other seeded winners included No. 5 Simona Halep of Romania, who beat No. 26 Kiki Bertens of Netherlands 6-4, 6-3, and No. 4 Angelique Kerber of Germany, who stopped Carina Witthoeft of Germany 7-6 (11), 6-1.
No. 19 Dominika Cibulkova of Slovakia ousted Eugenie Bouchard of Canada 6-4, 6-3. No. 28 Lucie Safarova of Czech Republic also advanced to the fourth round, outlasting Jana Cepelova of Slovakia in a marathon third set 4-6, 6-1, 12-10.
No. 11 seed Timea Bacsinszky of Switzerland beat Monica Niculescu of Romania 4-6, 6-2, 6-1 in another second-round match that was suspended by rain.
The All England Club announced that matches will be played on Wimbledon's middle Sunday for only the fourth time in the tournament's 139-year history.