A covert policeman told a court that he had two guns pointed at him by fellow officers after Jean Charles de Menezes was shot dead on a Tube train.
Mr Menezes passed through the barriers followed by police officers
Surveillance officer "Ivor" was holding onto Mr Menezes when armed police on the train killed the Brazilian.
Ivor, whose identity is protected, told the Old Bailey he was wearing virtually the same clothes as the suspected suicide bomber on 22 July 2005.
The Metropolitan Police deny breaking health and safety laws.
Two elite firearms officers shot Mr de Menezes, an electrician, seven times on a train at Stockwell Underground Station fearing he was one of the men responsible for the previous day's failed suicide bombings.
Ivor, who was carrying a rucksack at the time of the shooting, told the hearing that it was a "shocking incident".
His superior officer, codenamed James, was worried that Ivor could have been shot as his attire was so similar to Mr de Menezes.
The prosecution allege the Metropolitan Police put the public at risk by allowing their suspect to travel from his home to the station before they intervened.
Mr Menezes was pictured entering Stockwell tube
One of the suspects was linked to the block of flats where Mr de Menezes lived.
The Metropolitan Police say that officers did their best in extraordinary circumstances - and that while the shooting was a mistake, it was not a crime.
Ivor told the court he was one of the surveillance officers who followed Mr de Menezes after he left his home and headed to Stockwell station.
He said he joined the same London Underground train as the Brazilian and sat a few seats away as armed police rushed onto the platform.
He told the court how he prevented the train door from closing and identified Mr de Menezes to two armed police.
Although he had never met the officers, Ivor told the jury that he recognised them from their weapons and from what he knew of the unfolding operation.
"I shouted he's here and indicated to Mr de Menezes with my right hand," he told the court.
"I then heard shouting including the word 'police'."
Pausing to warn family members of the evidence he was about to give, Ivor said he saw Mr de Menezes stand and advance.
He judged that he could have been a suicide bomber preparing to detonate a device - and that he needed to restrain him.
Two police officers followed Mr Menezes down to the platform
"I grabbed Mr de Menezes by wrapping both my arms around his torso, pinning his arms against his sides," he said.
"The right side of my head was against his torso, pushing him back into his seat. He appeared to stiffen up and he was not in a natural sitting position.
"I felt his head turn towards me and I was aware of a CO19 [firearms] officer kneeling on the seat to my left.
"I heard a gunshot very close to my left ear. I was hit by the shockwave of a firearm being discharged."
Ivor told the court how he was then dragged away by one of the armed officers.
Within seconds he had a long-barrelled gun "levelled against my chest" and a pistol against his head, he said.
"I held out my hands and shouted 'police'," said the covert officer.
"It's worthy of note that I was dressed virtually identically to Mr de Menezes. Denim jacket, denim jeans."
The officer said he was also carrying a rucksack, unlike Mr de Menezes, who only had a newspaper.
Only when he had been dragged against the platform wall and was able to produce his chequered police cap did the danger to him pass, he said.
"I could hear several gun shots, screaming," he told the court.
"The scene was extremely violent, extremely noisy, obviously distressing - with members of the public emptying the carriage. There was gun smoke. It was an obviously shocking incident."
Asked in cross-examination why he had moved to alert the firearms officers, he said: "My actions were instinctive, based upon a genuine attempt to protect the public."
The case continues.