A taxi driver grabbed what he believed to be a gun from a man trying to rob him, a court has heard.
Derek McCann (39) produced an imitation firearm after flagging down the taxi, but was knocked off balance when the driver braked and tried to take the firearm from him.
The pair continued to struggle after getting out until another taxi driver came to his colleague's assistance, kicking the gun out of McCann's hand.
McCann, of Walkinstown Park, Walkinstown, pleaded guilty at Dublin Circuit Criminal Court to attempted robbery at Clogher Road, Dublin 12, last June 2.
Judge Melanie Greally noted that the incident had a considerable effect on the taxi driver, who no longer works nights.
The judge gave McCann credit for his guilty plea and co-operation and took into account his drug addiction, family support and the progress he has made while in custody.
She imposed a five-year sentence backdated to last June, when he went into custody.
McCann, who has previous convictions for burglary, assault, theft and handling stolen property, was on a suspended sentence at the time.
Gda Damien Quirke said McCann flagged down the taxi and asked to be taken to Clogher Road.
He and the driver spoke about football until McCann pulled up his hood and produced what appeared to be a gun.
He told the driver "This is a robbery" and issued directions on where to drive.
The driver unlocked his seat belt before suddenly braking and knocking McCann off balance. He grabbed the gun and realised it was made of plastic.
McCann tried to get into the driver's seat and there was a further struggle until he attempted to run away.
The driver believed he had the car keys and gave chase, tackling McCann to the ground.
Another driver kicked the imitation firearm out of McCann's reach before ringing gardai. The drivers held McCann, who was making threats, on the ground until officers arrived.
David Staunton, defending, said the offences were fuelled by a desperation to fuel his drug addiction and pay his drug debt.