Ian Hamilton, 30, pointed it at Neil McIntyre, 31, in Kilwinning, Ayrshire, in July 2016.
Hamilton, from Kilwinning, said "you're getting robbed" as he tried to force Mr McIntyre to hand over his takings.
He was jailed for 26 months after earlier pleading guilty to assault with intent to rob.
Hamilton, approached Mr McIntyre's ice cream van as it was parked in the Pennyburn area of Kilwinning, Ayrshire, at 15:30 on 3 July last year.
He asked for "20 fags" while holding his hand behind his back, then pulled the gun out.
Despite having the gun pointed in his face, Mr McIntyre grabbed the weapon but Hamilton managed to keep hold of it.
Mr McIntyre drove away from the scene and called police.
An investigation was launched but it was not clear who was responsible as McIntyre only recognised Hamilton as someone local to the area and did not know him personally or know his name.
Later that day, Hamilton was found by his girlfriend asleep face-down on top of his bed, with the gun next to him.
Never having seen the weapon before, she put it in the kitchen cupboard.
He had stolen the weapon, which was a ball-bearing gun, from his friend that morning during a drinking session.
Hamilton contacted Mr McIntyre via Facebook the following morning to apologise - revealing his identity and admitting what he had done.
His message, which he sent to Mr McIntyre's business page Neil's Ices, read: "Alright bud. Just wanted to say soz for pointing that gun at you, it was only a toy.
"It's a bit daft, I know, but I had a bevvy in me and I thought it was funny.
"I know it's not, though.
"I've got rid of it now so it doesn't cause any problems."
At Dumbarton Sheriff Court, defence solicitor Fraser Alexander said: "His position is that this was a joke.
"He was extremely under the influence of alcohol.
"The position is that he was drinking, the night before, heavily, woke the following morning and continued to drink, which resulted in him being extremely intoxicated. "
Mr Alexander added: "He does not seek to use it as an excuse for his conduct - he recognises his consumption of alcohol is his problem.
"This is not the behaviour one would expect from a man that comes from the background Mr Hamilton comes from."
He added that Hamilton had lost his job as a result of his crime.
A TSB bank manager who pulled a gun on an ice cream seller, then sent him a Facebook message saying sorry, has been jailed.