Bolt, 29, had won the 100m and 200m in Rio and is the only man to win all three sprint events at three Games.
He combined with Asafa Powell, Yohan Blake and Nickel Ashmeade to finish in 37.27 seconds.
Japan won a surprise silver and the USA were disqualified to hand Canada bronze and lift Britain up to fifth.
“There you go. I’m the greatest,” said Bolt, after bringing an end to one of the most astonishing Olympic careers of all time.
In February, Bolt confirmed he would retire after the 2017 World Championships and will not compete at Tokyo 2020, at which point he will be 33.
His haul of nine gold medals is the joint highest among Olympic athletics, equal with USA sprinter and long jumper Carl Lewis and Finnish long-distance runner Paavo Nurmi.
“I’m going to stay up late and have fun. I never knew this would happen when I started out,” Bolt told BBC Sport.
“My team came through for me tonight. As long as we got the baton round, it was never in doubt.”
Blake made an attempt to persuade 100m and 200m world record holder Bolt to continue for another four years, saying: “Usain needs to be immortal and he is immortal. I will encourage him to come back for 2020.” (Courtesy BBC)