Kenya-born American Paul Kipkemoi Chelimo claimed the bronze. It doesn't quite sink in until you compete here and cross the line - I had a couple of minutes to myself - that this is it.
The British runner, 34, added a silver to the gold he won in the 10,000 metres at the London Stadium last week.
Farah, who had not lost a final in 2,176 days, having also won the 10,000m and 5,000m at the 2013 and 2015 World Championships, is due to retire from track events at the end of the month, after the Diamond League final in Zurich, to focus on the marathon.
"I have a few more races on the track and then I will take a short break and then this chapter of my life is closed".
Farah, who is unbeaten in 5,000m global finals since winning the 2011 world crown, admitted to being exhausted but said he took his lead off a Kenyan catchphrase. That's what they did tonight, and the better man won on the day.
Farah did a little boxer's routine as he took to the line psyching himself up for another bruising battle like the 10,000m where he was spiked and nearly elbowed off the track.
Patrick Tiernan pushed the pace with three laps left and took a substantial lead, but the pack sped up with two laps to go and easily caught up. "I feel happy that I ran with Mo Farah".
That effort may well have taken more out of him that Farah himself had realised.
Pearson delivered the ideal championship performance too, her 12.59 seconds run from the front and enough to hold off the American Dawn Harper Nelson, with Germany's Pamela Dutkiewicz beating world record holder Kendra Harrison for the bronze.
Preview: Usain Bolt, the superstar who made athletics fun and watchable for the past decade returns to the track for the final time Saturday to run on Jamaica's 4x100-meter relay team. That he finishes with silver on the track clearly wasn't the farewell he had planned.