A police officer said he thought Sheku Bayoh had killed his colleague while they were trying to restrain him, an inquiry has heard.
Pc Ashley Tomlinson, 30, was one of the officers first on the scene after Mr Bayoh was reported carrying a knife in Hayfield Road, Kirkcaldy, in May 2015.
He said he feared for his life and thought "this is it, I'm not going home" when faced with attempting to restrain the 31-year-old.
Mr Bayoh died shortly after being restrained by police officers.
At a public inquiry into his death, being held in Edinburgh, Pc Tomlinson, fighting back tears, said he thought Mr Bayoh had killed his colleague Pc Nicole Short while they were trying to restrain him.
Describing the incident, Pc Tomlinson said he twice sprayed Mr Bayoh with CS spray in an attempt to control him, but it had no effect.
He then saw Mr Bayoh strike Pc Short, whom he said was not wearing head protection, 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," Mr Tomlinson said.
"She put her arms out and took a dive towards the road."
Pc Tomlinson described her action as "like a child going down a slip and slide".
"What I remember is she tried to push herself up then he (Mr Bayoh) stamped on her back which has caused her basically..."
After a brief silence, Pc Tomlinson, getting emotional, then added: "I thought he had killed her."
He continued: "I used my baton to deliver a blow. When you're dealing with something like that you can't run away."
Mr Tomlinson said he then struck Mr Bayoh in the head area with his baton.
"That didn't stop him, so I delivered two more baton strikes," he continued.
"That was enough to get him to turn around and look at me."
The witness said Mr Bayoh then faced him with his arms up "in a boxing position" which he said prompted him to strike the detainee another two times to the arms.
Angela Grahame QC, senior counsel to the inquiry, asked the witness how he felt when faced with Mr Bayoh, to which he replied: "In my mind, I thought, f***ing hell, this is it."
He continued: "The next thing I remember is Pc Walker coming into my view from my left, and, I don't know how to describe it other than a sort of bear hug wrestle thing to basically knock Mr Bayoh off balance and take him to the floor."
The inquiry then heard how Pc Walker was at the upper half of Mr Bayoh's body while Mr Tomlinson was at his feet.
The witness said he then struck Mr Bayoh's Achilles tendon area with his baton as a form of "pain constraint" to try and get a form of response from the detainee.
After no reaction, Mr Tomlinson said he then discarded his baton and straddled Mr Bayoh's legs and tried to handcuff his right hand.
After losing his balance, he pressed his emergency button to alert the police control room.
Mr Bayoh's family believe race played a part in their relative's death.
The inquiry is examining the immediate circumstances leading to the death of Mr Bayoh, how the police dealt with the aftermath, the following investigation, and whether race was a factor.
Earlier in evidence, Ms Grahame asked Pc Tomlinson: "What difference, if any, did it make that the man said to have had the knife was black?
"It made no difference at all," he replied.
She added: "Was that a factor in relation to your assessment of the situation on the route to Hayfield Road?"
To which Pc Tomlinson replied: "No."
The inquiry, before Lord Bracadale, continues.
Don't miss the latest news from around Scotland and beyond - Sign up to our daily newsletter here .