Emir Tzourtzi, aged 24, from Cintra Park, London; Kevin Paloka, 24, from Challis Way, London and 21-year-old Hasa Klevi, of no fixed abode, threatened their victims during an incident in Ellerker Avenue, Hexthorpe, in the early hours of Saturday, June 9.
The three men then fled the scene in a car, which was later stopped by the police near Huddersfield, where they were arrested.
An initial search of the car found an imitation firearm and machete and all three men were initially charged with affray, and firearms and weapons offences.
During another search a loaded handgun was found hidden inside the car.
Paloka was sentenced to 15 years for affray and firearms offences.
Tzourtzi and Klevi were both sentenced to seven years.
Detective Constable Rob Scarrow, of Doncaster CID, said: “I am extremely satisfied with the severity of the sentences handed out in relation to these offences.
“The offenders subjected the victims to a terrifying ordeal, and I am glad the sentence reflects the fact that behaviour like this will not be tolerated.
“The sentences also show that although no shots were fired, and nobody was injured in the incident, being in possession of a firearm will result in a severe sentence on conviction.
“I hope this discourages anyone who is considering carrying a firearm or imitation firearm from doing so.”