The four-time Olympic champion ran a valiant race in his final appearance on the track at a major championship but could not quite catch Ethiopia’s Muktar Edris.
Farah, who is planning to turn his attention to road racing, completed the 10,000m/5,000m double at the 2012 and 2016 Olympics, and the 2013 and 2015 worlds.
He claimed the 10,000m title once again last Friday, only to suffer his first loss in a final for 2,176 days on Saturday night in front of another huge London Stadium crowd.
Farah normally takes charge on the final lap but this time, following a tactical affair, he found himself playing catch-up over the final 400m as Edris and his fellow Ethopian Yomif Kejelcha led the way.
It looked at one point as if Farah may not even make the podium but he bravely challenged up the inside in the straight and managed to overhaul two of his rivals.
But Edris kept going strongly and triumphed in 13mins 32.79secs, with Farah second in 13:33:22 and Paul Chelimo of the United States third.
An emotional Farah collapsed on the track after the race but recovered and accepted his defeat in magnanimous fashion.
“I thought it might be possible (to win), but my legs had had it,” he said.
“I got boxed in early on – it doesn’t normally happen – but I got boxed in early and couldn’t get out.
“It’s been amazing. It’s been a long journey but it’s been incredible.
“To be honest with you, it takes so much out of me. It’s not an excuse, but it took a lot more out of me than I realised.
“Tactically, I was trying to cover every move.
“They had the game plan, one of them was going to sacrifice themselves. That’s what they did tonight, and the better man won on the day.
“I gave it all, I didn’t have a single bit left at the end.”
Farah is due to retire from the track at the end of the month, after the Diamond League final in Zurich, to focus on the marathon.
His British team-mate Andrew Butchart finished eighth in 13mins 38.73secs.