American Noah Lyles, 19, equalled the world-leading time of Wayde van Niekerk by winning in 19.90 seconds.
Lyles' compatriot LaShawn Merritt was second in 20.27, with Gemili crossing in 20.35 after being run down following a fast start.
Elsewhere, Jamaica's Elaine Thompson won the women's 100m in 10.78, which is the fastest time of the year.
Thompson, who won 100m and 200m Olympic gold in Rio, streaked clear to finish ahead of the United States' Tori Bowie (11.04).
Shaunae Miller-Uibo of the Bahamas ran a world-leading time of 49.77 in the 400m, as Britain's Anyika Onuora (53.98) finished last.
There was disappointment for another Briton, high jumper Robbie Grabarz, who cleared his first attempt at a height of 2.20m but went out after three failures at 2.24m.
In the men's long jump, South Africa's Luvo Manyonga set a Diamond League record of 8.61m.
Great Britain's Adam Gemili claimed third place in men's 200m at the Diamond League event in Shanghai.