The 29-year-old had collected the weapon from another man just 12 to 15 minutes before he was shot dead, Snaresbrook Crown Court in north-east London was told.
Mr Duggan's fatal shooting in Tottenham, north London, on the evening of August 4 last year resulted in disorder across the capital and other English cities over the following days.
Details of what happened that night emerged at the trial of Kevin Hutchinson-Foster, 30, who denies selling or transferring a prohibited firearm to Mr Duggan between July 28 and August 5 last year.
Edward Brown QC, prosecuting, told the court that the "lethal" BBM Bruni Model 92 handgun, which had been modified to take 9mm bullets, was found by police at the scene of the shooting.
He said: "It had been in the possession of a man named Mark Duggan. It was loaded - it had a bullet in its magazine.
"The evidence demonstrates that gun at that scene had been passed to Mark Duggan by this defendant, Kevin Hutchinson-Foster, shortly before the mini-cab in which Duggan was travelling was stopped by police in Ferry Lane in Tottenham Hale.
"Mark Duggan was shot and fatally injured by the police as a result of his possession of that gun and what he was thought to be about to do with it."
He added: "Hutchinson-Foster, some 12-15 minutes before Mark Duggan was stopped, supplied that gun to Mark Duggan, him having travelled to him to collect it as had been arranged."
Mr Duggan took a minicab to the area where a girlfriend of Hutchinson-Foster's lived to collect the gun, which was hidden in a shoebox, the court heard.
The prosecutor said telephone evidence showed that the two men contacted each other as Mr Duggan travelled across east London from Hoxton to Leyton.
After the gun was handed over, Mr Duggan continued towards Tottenham Hale, taking the weapon out of the shoebox at one point during the journey, the trial was told.
Mr Brown said Hutchison-Foster had used the same gun six days earlier to threaten and beat another man, but when he was arrested by police he lied about his possession of the weapon and his links to Mr Duggan.
The prosecutor told the jurors it was not for them to decide the rights and wrongs of Mr Duggan's shooting, which are due to be considered by a separate jury at an inquest early next year.
He said: "The death of Mr Duggan on August 4 last year has been regarded as the event that sparked the riots in north London, which then spread across London and then to other cities, and which attracted widespread publicity in the United Kingdom and abroad."
The trial continues.