Gatlin, who has served two doping bans and won silvers behind Bolt at the last two world championships, clocked 9.92 seconds, with teammate Christian Coleman winning silver in 9.94sec.
Bolt suffered a dreadful start and could only claim bronze in 9.95sec.
"I'm sorry I couldn't end it on a winning note, but I want to thank you for your support," said Bolt, who embraced Gatlin after they streaked through the line with no clear victor immediately apparent. "It's been a wonderful experience as always."
Gatlin was afforded the same rough reception as he had in the heats and semi-finals, loud boos and jeering ringing around the same stadium where in 2012 his rivalry with Bolt was presented as 'good against evil', given the American's doping-tainted past.
"I tuned it out [the boos] through the rounds and stayed the course," said Gatlin. "I did what I had to do. The people who love me are here cheering for me and cheering at home. It is Bolt's last race. I have had many victories and many defeats down the years. It is an amazing occasion. We are rivals on the track but in the warm-down area we joke and have a good time."
Sprint king Usain Bolt relishes looming retirement
The jeering did indeed continue unabated after it became clear Gatlin, a sprinter whose past divides track and field, had gatecrashed Bolt's party.
Gatlin initially put his finger to his pursed lips as if to hush the crowd, before dropping to his knees to bow down to Bolt.
"The first thing he did was congratulate me and say that I didn't deserve the boos. He is an inspiration," said Gatlin of Bolt.
Coleman added: "It was an historic moment for me to beat Bolt who has taken this sport to another level and who I watched as I grew up. A humbling experience. I'm delighted for Justin as we have bonded and become close. I was impressed by the way he handled the pressure and the crowd."
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ