Peter Donnelly, of The Green, Larch Hill Apartments, Santry, has pleaded not guilty at the Central Criminal Court to murdering Edward Flanagan at the same address on June 16, 2011.
He has also pleaded not guilty to possession of a Baikal 9mm automatic pistol and three rounds of .38 calibre ammunition at the same address on June 15, 2011.
Gary McMahon told Eileen O'Leary, prosecuting, that he and three other men were in the accused's apartment after spending the day drinking cans in a field behind Belcamp College in Coolock. He said he knew the victim for five years and the accused for a year or two from working on building sites.
On the morning of June 15, 2011, he said he went to Cullens field to meet Donnelly and another friend of theirs.
Mr McMahon said the deceased, whom he referred to as Ned Flanagan, came up after about an hour and the four were sitting around drinking in the afternoon.
He said they decided to go to Donnelly's apartment to continue drinking because it was getting cold.
Mr McMahon said they watched the film Lock, Stock And Two Smoking Barrels and when it finished they started listening to the radio.
He said Donnelly and Flanagan were dancing in the middle of the room and that everything was okay, then the dancing stopped, he said, and there was an argument between the two men.
I just heard the two of them bickering at each other, Mr McMahon told the court.
The two of them were having words and Peter left the room and came back, he added, stating Donnelly had gone into the bedroom.
He came back out shouting and I just heard a bang. I just heard a bang and ran out of the room, he said.
He said Donnelly was just mumbling words but he could not recollect what he was saying. He said he caught a glimpse of Donnelly with a black gun at the back of the couch where Mr Flanagan was sitting.
The court heard the deceased had no home and that Donnelly would take him in. Mr McMahon agreed he had said to gardai in a statement that he thought the accused was "only joking". The trial continues.