Ryan Holden, 20, said he watched from the other side of a street in Salford, Greater Manchester, as Kiaran Stapleton, 21, fired the fatal shot at close range.
The two men had been walking home from Manchester when they came across Stapleton's victim, Anuj Bidve, 23, walking with a group of friends.
Mr Holden told the jury at Manchester Crown Court: "Kiaran asked he could borrow my hat.
"He put my hat on and when we had gone down the road we saw a group of people on the other side of the street. I didn't really pay them much attention. I saw them and that was about it.
"We just got literally parallel and Kiaran said to me 'Wait here a minute'.
He crossed over and I saw his arm make a kind of gesture as if he was asking for the time.
"The next minute he put his arm in his jacket and reached his arm out. I heard a loud bang. He was stood right in front of them.
"I just ran straight away as soon as it happened. It was mad - it happened in a split second. I was on my toes and I just ran."
He added: "I don't know what I was thinking - I can't explain how I was feeling. The bang was loud - not like the sound when you slap someone. I thought he had shot him."
Mr Holden said his friend caught up with him as he ran, and together they went to Stapleton's house where Stapleton told him: "Shut the f*** up. Don't fold on me".
Stapleton showered and then told his friend to do the same. He then gave him some fresh clothes.
"I did't want to say anything to him about what had happened…I was pretty shocked and it didn't really kick in until the next morning".
Mr Holden returned home two days later, feeling "tired, drained and proper horrible".
"My mum came in and looked at me. I just went over to her and said `I was there the other night`. I had a feeling she knew from the way she was looking at me".
Stapleton, who identified himself as Psycho at an earlier hearing, has admitted manslaughter on the grounds of diminished responsibility. But he denies murder.
The trial continues.