Bolt received the baton with Jamaica in third, but halfway down the finishing straight the towering sprinter pulled up clutching his left thigh.
Bolt received the baton with Jamaica in third, but halfway down the finishing straight the towering sprinter pulled up clutching his left thigh, eventually doing a forward somersault to the ground, to gasps from the 60,000 sell out London Stadium.
The British quartet of Chijindu Ujah, Adam Gemili, Daniel Talbot and Nethaneel Mitchell-Blake claimed gold in 37.47 seconds, with the Justin Gatlin-led US four taking silver at 0.05sec and Japan a surprise bronze (38.04).
"He didn't tell us exactly what happened but from what I saw, it looked like a strain or a cramp of some sort," second leg runner Julian Forte said.
"He kept apologising to us but we told him there was no need to apologise -- injuries are part of the sport."
Newly-crowned 110m hurdles champion Omar McLeod, Jamaica's lead-off runner, added: "Everybody was jelly, everybody was pumped. (Bolt's injury) just happened. Usain Bolt's name will always live on."
Bolt missed out on his bid to retain his 100m title earlier in the week, losing out to Gatlin and silver medallist Christian Coleman, who ran relay anchor for the Americans on Saturday.
But hopes were high for Bolt's final competitive race, with Jamaica also boasting McLeod, Forte and 2011 world champion Yohan Blake in their line-up.
Jamaica were afforded a rousing welcome from the crowd, a relaxed-looking Bolt applauding the stands, with pictures of him constantly shown on the stadium's big screens.
Gatlin, who has served two doping bans, and the US team also including another convicted doping cheat, Mike Rodgers, and Jaylen Bacon were booed when introduced although the jeering was less pronounced than for the individual 100m event.
A close first three legs saw Britain, the United States and Jamaica, seeking a fifth consecutive world title, level-pegged for the final leg.
But there was to be high drama as a visibly swearing Bolt pulled up in obvious pain, allowing the Japanese quartet to edge in for third.
The result means Bolt, 100 and 200m world record holder, finishes his career with 14 world career medals, one behind American Allyson Felix, to go with eight Olympic golds.
Amid wild home celebrations, Bolt was attended to by medics, but refused a ride in a wheelchair off the track, instead finally getting up and limping alongside his teammates through to the finish line and then off into the bowels of the stadium for treatment.
It was a sad exit for an athlete who has lit up the track when the sport has been dragged through its worst-ever crisis, racked by doping and corruption scandals that went to the very heart of athletics' governing body.
And what a gaping hole his absence will leave, no matter how brave a face the IAAF try to put on it.
Since confirming his sprinting dominance with triple gold at the 2008 Beijing Olympics, Bolt spent nine seasons amassing 19 global golds, 13 of which have come in individual events.
Allied with a charismatic personality, it has guaranteed Bolt recognition as one of the world's most successful sportsmen. Last year alone he earned $34.2 million, according to Forbes.