The researchers created a game where volunteers were chased through a maze by an artificial predator. If the participants were caught they received a mild electric shock.
The volunteers' brain activity was measured using functional magnetic resonance imaging.
The research found that humans, like other animals, alter their behaviour when faced with a threat depending on whether the threat is close or distant.
This is because different defence mechanisms are needed depending on whether simply being aware of the threat might be enough to protect ourselves, or whether we might need to fight or run away.
"Without fear, animals would not react to threats. This would be a poor survival strategy and make it more likely that the animal would be eaten and not pass on its genes," said Dr Dean Mobbs, the lead author of the study.
"The most efficient survival strategy will depend on the level of threat we perceive. This makes sense, as sometimes being merely wary of a threat is enough, but at other times we need to react quickly.
"The closer a threat gets, the more impulsive your response will be - in effect, the less free will you will have."
The results of the Pac-Man experiment show that the fear response moves from the strategic areas of the brain towards more reactive responses as the artificial predator approaches.
When the artificial predator was in the distance, the researchers observed activity in lower parts of the prefrontal cortex just behind the eyebrows.
Activity in this area, known as the ventromedial prefrontal cortex, increases during anxiety and helps control strategies on how to respond to a threat.
However, as the predator moved closer, the brain activity shifted to a region of the brain responsible for more primitive behaviour, namely the periaqueductal grey.
This area is associated with quick-response survival mechanisms, which include fight, flight and freezing. This region is also associated with the body's natural pain killer, opioid analgesia, preparing the body to react to pain.
Although this natural defence mechanism is beneficial in evolutionary terms, Dr Mobbs believes that malfunctions in the system might help explain why some people suffer from anxiety disorders and panic attacks.
"When our defence mechanisms malfunction, this may result in an over-exaggeration of the threat, leading to increased anxiety and, in extreme cases, panic," he said.
"Although brain-imaging studies like ours cannot directly help to cure such disorders, they do improve our understanding of how the emotional system operates. This is the first step to helping people with anxiety-related disorders."
Cotton seedling freezes to death as Chang'e-4 shuts down for the Moon's 14-day lunar night
Fortnite easily out-earns PUBG, Assassin's Creed Odyssey and Red Dead Redemption 2 in 2018
Meteor showers as a service will be visible for about 100 kilometres in all directions
Saturn's rings only formed in the past 100 million years, suggests analysis of Cassini space probe data
New findings contradict conventional belief that Saturn's rings were formed along with the planet about 4.5 billion years ago