A 'memory stick' with a torch function was found in the jacket pocket of Serwan Abdulkarim, 36, by police officers who stopped a van he was driving shortly after 2am on March 12, 2020.
Police were looking for suspects of an earlier fast-food restaurant burglary in Worthing, West Sussex and believed Abdulkarim may have been involved, Leeds Crown Court heard.
The item was analysed by a ballistics intelligence team and found to be a firearm which was charged, prosecutor Matthew Moore-Taylor told the court.
Dad-of-three Abdulkarim - who was originally from Kurdistan but now lives on Cowper Road, Leeds - was arrested by officers and interviewed, where he offered 'no comment' to questioning.
Abdulkarim maintained the torch had been found in the driver's door of the van and not in his pocket.
He told the probation service he was in the process of making a delivery and believes the stun gun must have fallen out of one of the items he was delivering.
Abdulkarim continues to deny the offence, Michael Walsh said during mitigation.
"Whatever happened here he allowed himself to be put in a position where he is vulnerable to this happening", Mr Walsh continued.
"He has to be more careful.
"That is a lesson for him whatever the situation."
Abdulkarim appeared before magistrates where he was found guilty of possession of a weapon for the discharge of a noxious liquid/gas/electrical incapacitation device/thing following a trial in his absence.
Sentencing Abdulkarim at Leeds Crown Court on Wednesday morning (May 11), Recorder Christopher Rose said: "You were stopped driving a transit van.
"Police expected you may have been involved in a burglary.
"That plays no part in my approach to the sentence.
"When [police] searched you they found you were in possession of a small black torch which turned out to be a stun gun.
"That is a prohibited firearm
"You argued the stun gun had not been found on you, but the driver's side door.
"You continued to deny the offence, as is your right.
"The magistrates were sure you had been in possession of it and I sentence you for that today."
Abdulkarim was sentenced to a 12 month community order with 15 rehabilitation days and 150 hours of unpaid work.
He must also pay £100 in costs.
"You will know from your experience you must comply with those requirements", Recorder Rose added.
"It could well be you receive a custodial or suspended sentence next time."
A forfeiture order for the stun gun was also made by the judge.