World number one Djokovic trailed Kazakhstan's Mikhail Kukushkin by two sets to one and looked headed for a rare defeat before leveling the tie for Serbia in Belgrade.
Viktor Troicki clinched it with a comfortable 6-2 6-3 6-4 win over Kazakh number two Aleksandr Nedovyesov in the decisive fifth rubber.
Earlier, Djokovic was kept on court for just short of five hours in completing a vital 6-7 7-6 4-6 6-3 6-2 victory.
Struggling with an eye infection before the tie, an exhausted Djokovic could barely keep on his feet while being interviewed on court and paying tribute to the home supporters.
"You made the difference and gave me the energy to come out on top and I have to thank you for that," he said.
Second-ranked Murray also battled extreme fatigue and a Kei Nishikori fightback to beat the Japanese star in five sets, 7-5 7-6 3-6 4-6 6-3, his clash also lasting a shade under five hours
That clinched a 3-1 unassailable lead for the holder Great Britain, who will have to travel to Serbia for July's last eight clash after Wimbledon.
Murray, who won his opening singles and paired with brother Jamie to take the doubles, established a hard-fought two sets to love lead before seeing it disappear as he tired and Nishikori found inspiration.
Murray has not played since losing to Djokovic in the final of the Australian Open and has also been performing fatherly duties after the birth of his first child Sophia.
But in front of fervent home support in Birmingham he found a way to take the decider, breaking the record of the great Fred Perry with his 14th straight Davis Cup rubber win.
At four hours and 54 minutes, it was the joint-longest match of his career with the 2012 U.S. Open final against Djokovic, which he also won.
He told the crowd he would be heading straight home to celebrate Mother's Day with wife Kim and their four-week old daughter.
Earlier Sunday, the United States closed out victory over an understrength Australia team in Melbourne.
Injury and illness had left the Australians so depleted that captain Lleyton Hewitt had to come out of recent retirement to play in the doubles with John Peers.
That ended in a brave five-set defeat to the Bryan brothers, leaving the U.S. 2-1 ahead overnight.
John Isner beat Bernard Tomic 6-4 6-4 5-7 7-6 to take the Americans into the quarterfinals, sending down a record speed serve for a Davis Cup match on his way to victory.
In other last 16 ties, Switzerland, without Roger Federer and Stan Wawrinka, went down 5-0 to Italy in Pesaro, Argentina edged Poland 3-2 in Gdansk, while France thrashed Canada 5-0.
Lukas Rosol beat Alexander Zverev 6-2 6-3 6-1 to give the Czech Republic a 3-2 victory over Germany in Hanover, with Croatia edging last year's beaten finalist Belgium 3-2.