A police officer has claimed he thought Sheku Bayoh had killed one of his fellow officers and was going to kill him during their confrontation in Fife seven years ago.
PC Ashley Tomlinson, 30, gave evidence at the public inquiry into the circumstances of Mr Bayoh's death after being restrained by police.
He alleged Mr Bayoh punched PC Nicole Short to the ground and then stamped on her twice.
"I thought he'd killed her," he said.
The inquiry is investigating the circumstances of the death of Mr Bayoh in Kirkcaldy in May 2015, how police dealt with the aftermath, the investigation that followed and whether race was a factor.
It heard that PC Tomlinson twice sprayed Mr Bayoh with CS spray but it had no effect.
He then saw Mr Bayoh strike PC Short with his fist to the back of her head.
"That action caused her to fall or lose balance and she fell forward on to the road," he said.
She fell forward "like a child going down a slip and slide", he added. "She put her arms out and took a dive towards the road."
"What I remember is she tried to push herself up then he [Mr Bayoh] stamped on her back which has caused her basically.... I thought he'd killed her."
He said he saw him stamp on his colleague twice.
PC Tomlinson said that, at that point, he used his baton to strike Mr Bayoh on the head.
"It didn't stop him so I delivered two more baton strikes [to his arms]... but that stopped him," he said.
He said the first strike didn't cause him to move away from PC Short or to turn around, and he feared Mr Bayoh would stamp on her again.
The two additional blows were "enough to cause him to turn around and look at me," he added.
Mr Bayoh had his fists raised as he faced PC Tomlinson, the officer told the inquiry.
"I thought, this is it. I am not going home," he said.
'You've just saved my life'
Until this point, he thought he was the only officer left at the scene but then he became aware of the presence of PC Craig Walker.
"The next thing I remember is PC Walker coming into view from my left.
"[He used] some sort of like bear hug wrestle then to knock Mr Bayoh off balance and take him to the floor."
PC Tomlinson added: "I remember feeling - you've just saved my life."
Earlier, the officer told the inquiry that Mr Bayoh's race "made no difference at all" to his actions.
The family of Mr Bayoh, who came to the UK from Sierra Leone as a teenager, have claimed he was treated differently because of the colour of his skin.
PC Tomlinson, who has now been an officer for eight years, was 18 months into his two-year probation, when he was called to the incident.
PC Walker and Ms Short, who is no longer a police officer, have already given evidence.
The inquiry before Lord Bracadale continues.