An eagle-eyed garda on his way to court spotted a man discard a package containing heroin on the ground.
John Paul Joyce (38) panicked when he saw the garda and dropped the package, which contained three deals of heroin - writes herald.ie.
Judge John Cheatle imposed a four-month sentence which he suspended for 12 months.
The defendant, of St Cronan's Close in Swords, admitted before Swords District Court to possession of heroin.
The incident took place in Main Street in Swords shortly before 10.30am on February 17 last year.
Garda Thomas Murphy said he was walking to Swords courthouse when he saw Joyce standing outside the AIB bank.
Gda Murphy said that as he approached Joyce he saw him discard a number of packages.
The garda said he asked Joyce what was in the package, but the defendant told him he didn't know. Gda Murphy said the substance was later analysed and found to be heroin, with a street value of €80.
The court heard that the defendant had previous convictions for drugs-related offences.
Defence solicitor Fiona D'Arcy said Joyce had a very serious heroin addiction for nearly a decade, but had been doing well.
However, Ms D'Arcy said the defendant had suffered depression, was on medication and this incident was "a slip".
The court heard that Joyce was now back on his rehabilitation programme, and was stabilised on 60mls of methadone.
Ms D'Arcy asked the judge not to imprison Joyce, saying this incident was a one-off and the defendant was committed to staying off drugs.
Read more news of Dublin on our site.