My source for this answer is mostly Devereaux's discussion of "the Fremen Mirage" and other writing on his site about steppe nomads, which goes in-depth into what made the Mongols so powerful for their time - and why that time came to an end.
The answer has remarkably little to do with weaponry. The steppe nomad composite bow is an incredibly powerful weapon that strikes at long range, especially combined with Mongol skirmish doctrine that could break up formations. There's a reason that the major firearm users of this time period were Western European, rather than the people fighting the steppe nomads, and it's not because Western Europeans were smarter.
Gun-wielding armies had the same big weakness as bow-wielding armies: logistics.
Mongol armies could move many times faster than military formations organized by agrarian states - up to 60 miles per day compared to 10 miles for infantry armies. This is not only explained by their horses but also by their source of subsistence - soldiers could drink mare's milk from their mount, and when moving together with their herds, slaughter sheep to stay on the move for months. Meanwhile, an agrarian army can only carry about 10-20 days worth of rations for soldiers and animals. The steppe pony can survive on just grass; the larger European horse (to give one example) must be stall-fed. If you want to use firearms, you have to bring wagons of gunpowder and spare parts (it's much harder to fix a damaged musket than an axe in the field) further reducing your range.
So a Mongol army seemed like it could appear anywhere, while to attack the Mongols (either to chase their armies or to strike their civilian population and resource base) required taking an army into a steppe that could not sustain it for more than a handful of days. Mongols could therefore engage in battle pretty much on their own terms, and if they ever lost they could retreat, come back and try again with most of their strength intact (battles were won or lost based on morale and cohesion, rather than killing everyone, and wars were won through sieges and holding ground). The agrarians' slow-moving armies could not follow the Mongols into the steppe, and could not pull the same trick off with their own assets (farms and towns) for obvious reasons.
The Mongols were defeated when that logistical advantage was overcome. Partly this was due to the development of an Early Modern centralized state that could organize supply dumps, long-distance transportation, and more effective mobilization & training of its soldiers rather than relying on vassals to ride out with whoever they happened to have on hand. The firearm becomes useful only in this context - in the hands of a state able to organize manufacture, issue, doctrine development, training, and logistical support. But such a state does not need guns in order to win battles because its troops are already much higher quality. Its superior organization also means that it can hold ground in the steppe, and eventually settle it, to deny the Mongols pasture land in the long term and therefore win strategic victories that can meaningfully add up over time, which is how Muscovy was able to turn the stalemate at Ugra into eventual domination of former Mongol lands.
Meanwhile the Mongol pastoral way of life was about as optimized as it could be for their circumstances. Their bottleneck was not logistics or equipment, but population: every adult male is already a soldier, and already using the best weapon available. Even if they could increase their population, you can only graze so many horses (and sheep) on one plot of grassland before they eat all the grass (consider that every mounted rider needs several horses). The Mongols could not innovate their system to overcome the loss of their logistical advantage.