The eight-time champion was two sets up and had a match point in the third, but nearly three hours later he trudged off on the end of a seismic 2-6 6-7 (5/7) 7-5 6-4 13-11 upset. Anderson will take on the victor of Milos Raonic and American John Isner.
Khachanov overcame more misfortune as he held to level the third set at 2-2 despite Djokovic twice receiving the help of a net cord, but he could not survive more pressure two games later, scooping a backhand long to put his opponent on the brink. It's just different. I think this gives Anderson a better chance.
To stay in this year's Wimbledon he must beat a player who hasn't lost a set at SW19 since 2016, has faced just four break points in 12 sets at this year's competition, and is also the greatest tennis player of all time - Roger Federer.
Djokovic looked in control in the first set.
Anderson then held the 24th game to clinch one of tennis' most famous victories.
"He claims that he didn't see what Nishikori has done, but apparently he always sees what I do", Djokovic said afterward, "something that I don't think is fair".
The victory sends Anderson to Friday's semifinal, in which he'll face three-time Wimbledon champion Novak Djokovic, who turned back Kei Nishikori in four sets.
Like Nadal, who could strike Djokovic in the semis, Federer hasn't dropped during his charge to a 16th Wimbledon quarter-final, nearly surely a staggering record that will never be surpassed.
Kevin Anderson of South Africa reacts after losing a point in his men's quarterfinals match against Switzerland's Roger Federer, at the Wimbledon Tennis Championships, in London, Wednesday July 11, 2018.
But after failing to convert a match point in the third set, Federer allowed a rash of errors to creep into his game, particularly on the forehand side. In all, the two battled it out for over four hours.
Wednesday's other quarterfinals will pit Nadal against Juan Martin del Potro, while American John Isner will take on Canada's Milos Raonic for a semifinal berth.
Kevin Anderson reached Wimbledon quarter-finals for the first time in his career.
That didn't seem to affect his focus, though, and neither did a time violation he was given when serving at 4-2, 30-30 in the fourth set.