The 34-year-old Farah, also a six-time world champion who will now switch to road running, clocked 13min 06.05sec to defeat Paul Chelimo of the United States and Muktar Edris of Ethiopia.
However, Chelimo was later disqualified for obstruction with Ethiopia's Yomif Kejelcha promoted to third place.
Victory was particularly sweet as Edris had defeated him in the 5,000m final at the world championships in London two weeks ago, ending his streak of 10 gold medals dating back to the 2011 world championships.
It was also Farah's first career Diamond League trophy.
“I wanted to win, and it's amazing that I have won, but it was hard work,” said Farah.
“I will miss the track, the people, my fans. I have enjoyed running in stadiums for a lot of years, but now first of all I will enjoy being with my family.”
While Farah took the applause of the Zurich crowd, it proved a night to forget for controversial American sprinter Gatlin who captured the world 100m title in London.
Gatlin, who served a four-year doping ban from 2006-2010, wasn't jeeered as he was in London, where he gatecrashed Usain Bolt's farewell party, but was beaten into fourth place in 10.04sec with Britain's Chijindu Ujah taking victory in 9.97sec.
Ujah, part of Britain's 4x100m relay title-winning squad at the world championships, finished ahead of Ivory Coast's Ben Youssef Meite (9.97sec) with Ronnie Baker of the US completing the podium (10.01sec).
Schippers, Thompson beaten
Bahamas' Shaunae Miller-Uibo stunned world champion Dafne Schippers and Olympic gold medallist Elaine Thompson to win the women's 200m.
Miller-Uibo, who was only third in the event at the recent world championships in London, won in a time of 21.88sec ahead of Thompson (22.00) and Marie-Josee Ta Lou of the Ivory Coast (22.09), the silver medallist in London.
Schippers struggled home in fourth place (22.36).
It was the second shock failure of the season for Thompson, the Jamaican sprinter who captured Olympic gold in the 100m and 200m in Rio in 2016.
In the 100m at the world championships, she finished in a lowly fifth place.
However, she will get a last chance to redeem herself at the concluding Diamond League meet of the season in Brussels on September 1st when she runs in the 100m.
Bahrain's Ruth Jebet ran the second ever fastest women's 3,000m steeplechase winning in 8min 55.29sec.
The Kenyan-born Olympic champion, 20, was two and a half seconds off her own world record of 8:52.78 set in Paris in August last year.
Jebet had a disappointing world championships where she finished fifth but she bounced back on Thursday beating Kenya's Beatrice Chepkoech (8:59.84), the runner who famously missed the water jump barrier in London and had to retrace her steps.
World champion Emma Coburn of the United States was fourth in 9min 14.81sec.
Qatari high jumper Mutaz Essa Barshim struggled in the rain to improve on his season best of 2.40m set in Birmingham last week.
He still won with a clearance of 2.36m on his third attempt, some distance back from Javier Sotomayor's world record of 2.45m set in 1993.