The 30-year-old Italian won the event in 1:54.22 ahead of Australia's Ariarne Titmus and Sweden's Sarah Sjostrom, in third.
The 2008 Olympic champion claimed her eight consecutive podium and the fourth gold medal in the women's 200m freestyle.
She joined Katinka Hosszu and Sarah Sjostrom as the only women to win an event at least four times at the world champs.
'La Divina' showed one more time why she's the 'queen' of the distance.
Tears of joy
"I can't believe it, I can't believe it" Pellegrini said in tears after coming out of the water.
"I'm super happy because this is my last world championship. These are not tears of sadness, they are tears of joy.
"I've worked a lot over these years, I love working hard and I'm glad I can see the results.
"Katie Ledecky wasn't there today, but it was one of the most hard-fought races ever." - Federica Pellegrini
After winning the 200m title in Budapest two years ago, Pellegrini took a year off from her favourite distance to focus on speed events:
"I was criticised, but it worked out well. Also the strategy to arrive here only three days earlier paid off.
"For the first time today I watched the time ahead of my position.
"I swam in 1:54.22. If I had to pick an ideal time for the last race of my life, that would have been 1:54.00. But there's still time for that in Tokyo..."
Pellegrini will turn 31 on 5 August.
She told the Olympic Channel she plans to end her career next year at Tokyo 2020.
It will be her fifth consecutive Olympics and no female swimmer has ever reached this feat.
The reactions from the other medallists
400m world champion Ariarne Titmus wasn't properly satisfied with her silver:
"Based on training times, I probably thought I had a better swim. But what can you do? It's what you do on the day. Pellegrini was really good tonight. She's a true champion, a world record holder. For her to beat me, I'm ok". the Australian said.
"I have such high standards and I would have loved the gold, but it wasn't enough to earn that."
Sarah Sjostrom received oxygen on the pool deck after the race and later said she had a headache.
"The worst thing you can do when you feel like that is to lie down, you should try to move" she explained.
"So it got so much worse. I couldn't see anything. The doctor came to take my blood pressure and it was really bad. Then I said 'I was fine', but they wanted to carry me away... I think I actually need a doctor every race!"
"I couldn't have done anything better than that. I'm really happy with what I did both in the 200m butterfly and 200m freestyle, I did both my best races in the final. So I really proved that I'm at my best when it really matters. It was bronze today and silver in the butterfly, but I know I'll always do my best times when I go in the finals."