Media playback is not supported on this device
Almaz, 24, had won the 10,000m in world record time last week and had been expected to complete the 10,000m and 5,000m double.
But she was overhauled by Cheruiyot, 32, and her Kenyan compatriot Hellen Onsando Obiri, 26, who took silver.
Cheruiyot set an Olympic record time of 14 minutes 26.17 seconds. Britain's Eilish McColgan was 13th in 15:12.09.
"It's my fourth Olympics and I hadn't had gold. Today I said 'I am not going to lose'," said Cheruiyot, who was runner-up to Almaz in the 10,000m in Rio and the London 2012 5,000m silver medallist.
McColgan said: "Yes, I'm actually disappointed although it's good that I am disappointed. At the start of the year if someone had said that, I would have taken it.
"Looking at the other girls' personal bests I thought that I should be around the top eight and to come 13th, I'm really disappointed. I'm in better shape than that.
"To go and run 15:12, I don't think I've done myself justice but it was good experience and that burst of pace, I'm not used to doing it and I need to mentally get ready for it. "
Subscribe to the BBC Sport newsletter to get our pick of news, features and video sent to your inbox.
Kenya's Vivian Cheruiyot won a shock 5,000m Olympic gold as race favourite Ayana Almaz of Ethiopia took bronze.