The firearms officer who shot dead the ringleader of the 2017 London Bridge attack thought he would be killed when he challenged him, a jury has heard.
The officer told the Old Bailey inquest into the deaths of the attackers that he feared Khuram Butt would "stab me, kill me and get hold of my weapons".
Butt and two other men had just driven at pedestrians on the bridge and attacked people with knives in Borough Market - killing eight and injuring 48.
All three were shot dead by police.
The inquest is expected to go on for three weeks and, under law, must be heard by a jury.
In just 10 minutes, Khuram Butt, 27, Rachid Redouane, 30, and Youssef Zaghba, 22, ploughed down pedestrians on the bridge and brought chaos to Borough Market, carrying knives and wearing fake suicide belts.
Addressing the court anonymously, the officer identified only as BX46 said that as he arrived at the scene in an armed response vehicle at the end of a 12-hour shift, he was armed with a Glock 17 pistol, a Taser and a G36 carbine rifle.
He said he "feared the worst" when the call came in, and that as he approached with his window down, he could hear people saying "they're stabbing people".
He said he then saw an Asian man in a blue Arsenal top holding a large knife in a threatening manner.
Although he couldn't recall the exact words he used, he said he believed he would have shouted: "Armed police, stand still, drop the knife".
He said the attacker did not obey the command, so he moved back to create some space between them. But the attacker - later identified as Khuram Butt - came towards him, raising his knife.
"I believe his intention was to use the knife and stab me, kill me and get hold of my weapons. The knife was in a raised position, which gave me great concern," he said.
The officer said he then noticed Butt was wearing what looked like an improvised explosive device.
"They looked like vertical tubes, grey, around his chest. He was one to two metres away, a threat to me. Detonation would be fatal," he told the court.
The officer said he was not aiming for a particular part of the body when he pulled the trigger. He fired a number of shots and stopped when the attacker fell to the ground.
The court also heard from a second officer, identified as BX44, who told jurors that the incident at London Bridge was his first firearms incident.
He said he had been tasked with handing out weapons from the Armed Response Vehicle, but that as he got out of the car, he saw three Asian men coming towards the group, carrying knives.
He said he fired first at Butt because he thought he was about to kill BX46.
"The red dot [from the gun's sights] was on him but there was very little reaction and I was surprised he was still coming."
He said he continued to track him with his weapon, but he had to break away because he feared another of the attackers, Rachid Redouane, was about to kill another colleague, codenamed BX45.
"The red dot was on him. I fired shots and there was no immediate reaction. I carried on firing until I had to deal with the third threat of Youssef Zaghba.
"I was backing away trying to create a reactionary gap when I fired and fell backwards, and as I fell backwards I fired, and from the floor I fired through my legs up to his chest.
"I thought he was about to kill me."
Afterwards, he kicked Zaghba's hand away from his chest, because he assumed he was about to detonate what he thought was an explosive belt, before moving on to support BX46, he said.
BX44 said he thought Butt was dead, but minutes after the first burst of gunfire he saw his chest rise and fall.
"I did not see his hands but his arms started to move down slowly towards the suicide vest," he said. "I thought he was going to detonate. I fired shots. They were aimed shots."
BX44, who fired 17 shots, went on to help search for a fourth possible attacker and carried a woman who was having a seizure to safety.
He said he found three people in a cupboard during a search of the Black and Blue restaurant nearby.
The inquest continues.