Individual world champion James Guy swam a superb final leg after Dan Wallace, Robbie Renwick and Calum Jarvis had put Britain in contention.
The US were led off by swimming great Ryan Lochte but could not hold on.
"They've always been the best 4x200m team in the world but we really stepped our game up tonight," said Wallace.
"It always makes you confident to have the world champion anchoring your relay but I think we set him up pretty well and it was a great race."
Britain clocked a time of seven minutes 4.33 seconds to claim the nation's first ever men's relay gold at a World Championships, with the US and Australia completing the podium.
The US had won the event, which will be part of the Olympic programme in Rio next year, at the last five World Championships.
Guy, 19, won the individual title on Tuesday and took the British quartet from third to first on the final leg of the relay.
"The way things have been going in racing and training, the work is paying off," said Guy. "The personal bests are finally dropping down."
Britain now stand third in the overall medals table behind the United States and Australia with five gold, one silver and two bronze medals after six of eight days in Kazan.
In Friday's other events, Andrew Willis finished fourth in the men's 200m breaststroke but Lizzie Simmonds failed to progress in the 200m backstroke.
Ben Proud and Fran Halsall qualified for Saturday's 50m freestyle and butterfly finals respectively.

The incident was said to have happened as Mr Galloway gave a talk in the university's New King's building.
He tweeted that he had an "unknown substance in my eyes and lungs" but added later that he was "feeling better... just needed a good shower".
Police confirmed they had been called to a disturbance at 19:45.
Mr Galloway, who is from Dundee, also tweeted: "Someone calling themselves "Trans" and an "anarchist" led a five person attack on me on the platform at Aberdeen University. I continued."
He also said on Twitter that his pregnant wife had leapt forward to defend him.
A Police Scotland spokesman said officers had attended High Street in Old Aberdeen following reports of a disturbance.
"Inquiries are at an early stage and no further details are available at this  time," he said.

Tens of thousands of pilgrims joined him for the Way of the Cross ceremony, recalling Jesus' crucifixion.
Among the cross bearers were Syrian and Iraqi refugees, and Nigerians who had escaped Boko Haram persecution.
The service came a day after almost 150 people were killed in an al-Shabab attack on a Kenyan university.
"We still see today our persecuted brothers, decapitated and crucified for their faith in you [Jesus], before our eyes and often with our complicit silence," Pope Francis said, presiding over the ceremony at the Colosseum.
Earlier, he condemned the attack in Kenya, where Christians were singled out and shot, as an act of "senseless brutality".
In another Good Friday ceremony, Pope Francis listened as the Vatican's official preacher Raniero Cantalamessa denounced the "disturbing indifference of world institutions in the face of all this killing of Christians".
He too mentioned the Kenya attack, as well as the beheading of 22 Egyptian Coptic Christians by Islamic State (IS) militants in Libya in February.
Pope Francis has spoken out against the persecution of Christians before, saying that the world would be justified using military force to combat the "unjust aggression" by IS.
Great Britain's men overhauled the United States in a dramatic 4x200m freestyle relay final to win gold at the World Championships in Russia.
[NEXT_CONCEPT]
Police were called to the University of Aberdeen following reports that a group of protesters had thrown glitter over former MP George Galloway.
[NEXT_CONCEPT]
Pope Francis has condemned the "complicit silence" about the killing of Christians during a Good Friday service in Rome.