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.

Media playback is not supported on this device
Stokes smashed 158 from 131 balls and Taylor compiled a stylish 114 before both were retired out.
Nick Compton, batting at three, marked his return with 58.
That helped England recover from 56-3 as Alastair Cook managed only two and new opening partner Alex Hales eight.
Hales is set to become the eighth man tried at the top of the order since Andrew Strauss retired in 2012 when the first of four Tests against South Africa begins on 26 December.
In this first of two warm-up matches, the Nottinghamshire man faced nine balls, one of which was an edge through the slips, before the 10th took his off stump as he offered no stroke to Junior Dala.
Cook had already been trapped lbw Thandolwethu Mnyaka and, after Joe Root edged behind for a 28 scored exclusively in boundaries, the tourists were wobbling.
Enter Compton, given the chance at number three ahead of Gary Ballance, to play with the sort of control England require after the omission of Ian Bell.
He was eventually pinned lbw on the back foot, allowing Taylor and Stokes to push the innings into a higher gear.
Stokes, in particular, dished out some brutal treatment, going from 50 to 100 in only 38 balls. In all he struck 23 fours and five sixes, the last of which left the fielding side unable to find the ball.
When both men were called to the pavilion, Jonny Bairstow (35) and Moeen Ali (33 not out) were afforded some time at the crease.

The Executive Office said the move was made "to enable doctors to conduct a medical assessment".
Mr McGuinness was due to join the first minister on the trade mission.
A spokesperson said he was "fulfilling his responsibilities as deputy first minister working with his departmental political advisers".
"There has been no disruption to the work of The Executive Office during this period," added the spokesperson.
Sinn Fein leader Gerry Adams said: "I'm sure everybody who values his work will send best wishes to Martin, Bernie and their family.
"I met Martin as normal at Stormont on Monday. I have been in regular contact with him since and he is totally committed to fulfilling his duties."
Kenya's Vivian Cheruiyot won a shock 5,000m Olympic gold as race favourite Ayana Almaz of Ethiopia took bronze.
[NEXT_CONCEPT]
Ben Stokes and James Taylor both made unbeaten centuries as England reached 470-5 on the opening day of their warm-up match against a South African Invitation XI in Potchefstroom.
[NEXT_CONCEPT]
Deputy First Minister Martin McGuinness pulled out of a trip to China this week due to medical advice, it has been revealed.