UK OK's point is correct, it has more to do with self belief. And if you watch those races again, you will see that Mo just wanted it more than the other runners.
Teddington Brit's numbers are wrong. Often runners over-estimate how fast the top distance runners are in pure speed.
The ability to run a very fast last lap comes from a combination of practice and determination. Rupp just gave up on the last lap, but Farah fought to the death. In his mind he just wasn't going to settle for anything less than a Gold medal.
In physiological terms, the training that runners do should prepare them for a sustained fast finish. During a race, our muscle fibers are used in a sequence, with both fast and slow twitch fibers being used from the start to the finish. With practice, the ability to save the most powerful muscle fibers for the end of the race, whilst still using aerobic fast twitch (fast oxidative) fibers also, enables a runner to sprint longer and longer, so that the best conditioned runners can run the last lap at close to their 400m pace.
However this takes a lot of confidence and determination. And those two factors are the main things Mo Farah has developed in the last few years. With Salazar he has almost reached his peak.