Police found the illicit weapon at Alan Gilmour’s home after they stopped a car he was driving and detained him on suspicion of having drugs.
The gun was a converted derringer style pistol which originally discharged blank cartridges but had been modified to fire bullets.
Nine rounds of ammunition were also recovered during the search at a flat in Crowhill Quadrant, in Bishopbriggs, on the outskirts of Glasgow.
More than £8,000 in cash was found in the premises and a bag containing a further £7,100 was discovered under a seat in the car.
Cocaine was also found in a rucksack in the boot of the vehicle along with the common adulterant benzocaine, which is used to bulk out the drug.
A judge told Gilmour (27) this week that he was compelled by parliament to impose a minimum sentence of five years on him for the firearms offence.
Lord Burns jailed him for a further two years at the High Court in Edinburgh for drug crime and told him: “These are Class A drugs and people who distribute them in the way you did must be dealt with in a serious manner.”
Gilmour earlier admitted illegally possessing the gun and ammunition on October 16 last year, possessing the Class B drug Cannabinol and being concerned in the supply of Class A cocaine.
Police stopped Gilmour on October 16 in Bishopbriggs and as they approached the vehicle officers thought that he was trying to conceal something.
They found money, cocaine, scales and a notepad containing notations which appeared to be linked to the drug trade.
The total amount of cocaine recovered had a potential maximum value of about £8,000. Some of it was high purity which would likely be bulked out for onward supply.
Defence counsel Tony Lenehan said Gilmour had used drugs recreationally but developed an issue with gambling and started getting drugs on tick.
Mr Lenehan said he was called on to store items and having taken delivery of drugs he would pass them on to others.
The defence counsel said: “He is a painter and decorator. That is his trade. He is not a gangster or someone who is a career criminal.”
Lord Burns told Gilmour: “I still have difficulty in accepting that your role was limited simply to distribution.”
The judge said: “It seems to me inevitable to come to the conclusion from the notations and all the other paraphernalia in your house that you were deeply involved in the production and adulteration of drugs and the distribution of them.”