Kenneth Okafor, 20, was arrested with the weapon during a routine operation tackling anti-social behaviour on the Docklands Light Railway by British Transport Police officers.
He was stopped at All Saints station at around 5pm on Friday 4 October 2019.
Alongside the gun, he was in possession of a knife. A search of his house also found an array of equipment that could be used to build makeshift ammunition.
The handgun, although simplistic-looking, was forensically examined and found to be feasibly capable of firing this ammunition.
Officers investigating the case suggested the seized evidence showed an “unhealthy interest” in the manufacture and possession of firearms and ammunition.
Okafor, of Jeremiah Street in Tower Hamlets, London, was sentenced to two years in a young offender’s institution at Inner London Crown Court on Friday 6 November.
He had been found guilty of possessing a firearm, possessing ammunition and carrying a knife in a public place.
Detective Constable Mike Ganly, of British Transport Police, said: “Okafor had an unhealthy interest in firearms and ammunition – both have no place on the rail network where they can put other passengers at risk. He has now experienced the consequences and will serve time.
“We patrol the rail network constantly and carry out pre-arranged, intelligence-led operations on a weekly basis. Both ensure passengers can travel throughout the capital safely and that people committing offences are dealt with.”