The world number one, bidding for a fourth Wimbledon title and 13th major, suffered his earliest loss at a Slam since the 2009 French Open.
The 7-6 (8/6), 6-1, 3-6, 7-6 (7/5) third round defeat also ended Djokovic's Open era record run of 30 successive wins at the majors and his streak of having reached 28 consecutive Grand Slam quarter-finals.
"Sam played a great match. His game was brutal and I was overpowered today," said Djokovic who added that he "wasn't 100% healthy".
It was only a second win in 10 meetings for American Querrey, the world number 41, against Djokovic and it was constructed on an epic serving performance over two days after the tie had been suspended with him two sets to the good on Friday.
More From This Section
The 28-year-old sent down 31 aces -- 15 in the fourth set alone -- and saved 14 of 17 break points while unleashing 56 winners.
His reward is a last-16 clash with 34-year-old Frenchman Nicolas Mahut.
"It's incredible, especially to do it here at Wimbledon. I'm so ecstatic right now and so happy," said Querrey.
"He's so amazing, he's on the way to being possibly the best ever so you know he's mentally tough and going to come back."
Rain had saved 29-year-old Djokovic on Friday when the match was halted with him trailing by two sets after being comprehensively outplayed.
He had been here before. Last year, he was two sets to love down to Kevin Anderson in the fourth round before staging a thrilling comeback.
- Thunderous -
On the resumption Saturday, the US, Australian and French Open champion broke for 2-0 in the third set and backed it up with a service hold.
More rain returned after just 17 minutes of play with the top seed 4-0 ahead.
After two hours of shelter, Djokovic returned to grab a 5-0 lead and survive a blip before claiming the set, 6-3.
Querrey had to save three break points in the opening game of the fourth set and three more in the third for a 2-1 lead, his thunderous serve providing a welcome escape route.
Djokovic had two more chances to break in the fifth game before finally breaking through at the 12th time of asking for a 5-4 lead.
Djokovic served to take the set into the tiebreak and was ahead at 2/0 and 4/3 but the resolute Querrey still went to two match points.
The top seed saved the first, but ballooned a forehand wide and his fate was sealed to leave Rod Laver in 1969 remaining as the last man to sweep all four majors in the same year.