Of course, we learned later in TAS that Cyrano somehow obtained a "Glommer" from the Klingons that ingested or otherwise destroyed all the Tribbles. So that's how he picked them up.
The whole end premise is a punchline in search of an explanation that is about as durable as a wet paper bag, both at the end of the 1967 episode and the animated follow-up.
Spock mentioned 1,771,561 tribbles in the storage compartments, and if we assume all those tribbles and their offspring died off quickly due to the poisoned grain, that means venting the compartments into space gets rid of most of them. But…
The mystery factor is how many tribbles there are everywhere else on the station, which is unknowable without knowing how many Cyrano supplied the barman with and how quickly, and how much food there is for them on the station. Assuming he sold the barman only ten tribbles almost immediately, and enough food for them to all reproduce, there could be over ten million of them by the time Kirk gives Cyrano his sentence, and if they can't cut off the food supply pronto, maybe 100 million plus by then.
Assuming Uhura's Tribble was the only one brought aboard the Enterprise, and assuming all of them managed to find enough food to reproduce, Scotty would have ≈1 million of them to beam out, which would occupy maybe 150,000 cubic feet, which would be like a cube of fluff 50 feet to a side.
None of these factors in the unknown lifespan of tribbles, especially unfed ones, which suggests a mind-boggling number of fuzzy, rotting corpses to toss into space.