Christian Coleman took silver in 9.94 seconds while Bolt got bronze in 9.95.
"My start is killing me," Bolt said. "Normally it gets better during the rounds but it didn't come together."
Gatlin knows what Bolt has meant to the sport, graciously bowing in admiration in front of him - even after beating him. The two men, never really friends, warmly embraced and spoke.
"It's just so surreal right now," Gatlin said. "Usain has accomplished so much in our sport and inspired others."
When his victory sank in, Gatlin let out an almighty roar and then put a finger in front of his mouth for silence as the crowd continued to show him disrespect.
It was an amazing turnaround for Gatlin, who was the Olympic champion in 2004 before Bolt emerged and won an unprecedented three straight 100-meter titles at the Olympics.
Thirteen years later, Gatlin bounced back to win in the Jamaican's last individual race.In between, Gatlin's career was stopped twice for doping suspensions. Yet fighting controversy all the way since, he got perhaps his greatest gold at 35.
"It was almost like 2004 all over again," Gatlin said. "I won by a little margin, and to be able to come across the line is amazing."
The 60,000-sellout crowd at the Olympic Stadium, ready for a party in a race they were convinced Bolt would win, had to acknowledge a champion they relentlessly booed over the opening two days of the championships.
It turned into awkward scenes with the champion being overlooked for the bronze medalist."It's not about the crowd," Gatlin said. "I tuned it out through the rounds and stayed the course."
Bolt didn't smile any less afterward."It is just one of those things," Bolt said, showing his carefree demeanor even in defeat. "It has been brilliant."
Bolt was again slow out of the blocks in the final and came back strong, but he ended up short. When he ran out of steam, Gatlin gathered more."He knows how hard I work," Gatlin said. "Tonight was all about the W (win) and I managed to sneak it."
The 100 final was overwhelming, and so was the women's 10,000 as Almaz Ayana tries to turn massive victories into a tradition.After winning the Olympic title in Rio de Janeiro with a runaway world record, the Ethiopian made sure that her margin was even bigger at the worlds - make that three times as big.
Ayana won in 30 minutes, 16.32 seconds, 46.37 seconds ahead of Ethiopian teammate Tirunesh Dibaba. In track terms, that is more than 300 meters in a 10-kilometer race. Agnes Tirop of Kenyua took bronze.Ayana came into the championships swirled in mystery.
She had no official time for the 10,000 this season and had been hampered by injury."I have been sick this year and didn't expect it," Ayana said. "In fact, this was my first race of 2017."
In the long jump, Luvo Manyonga of South Africa took gold with a leap of 8.48 meters, holding off Jarrion Lawson of the United States by 4 centimeters and going one better than his silver at last year's Olympics.Ruswahl Samaai, also from South Africa, took bronze with a jump of 8.32 meters.
Manyonga lost by one centimeter at the Olympics, but he no longer wanted to be reminded of that."I do not feel like thinking about the last attempt in 2016, this brings back bad memories," Manyonga said. "It does not matter anymore because I have the gold medal now."Also, Andrius Gudzius of Lithuania won his first major discus title. He held off favorite Daniel Stahl of Sweden by two centimeters.