Better fortifications, unfavorable terrain, improved tactics
Main advantages of Mongols were Mongol composite bow and Mongolian horse. Mongols were primarily numerous light cavalry, they used their bows to attack from significant range. Their horse were not faster then European ones, but they could endure more. Each Mongol warrior had couple of them, so Mongol army moved surprisingly fast, appearing unexpectedly, and had fresh horses for battle, unlike their European counterparts. Mongols did have other weapons (lances for example) and siege machinery, but these were not more advanced then similar equipment used by Europeans. One more advantage Mongols had was their relative unity, compared to European kingdoms that were often divided between monarchs and powerful noble houses. Finally, Mongols often used psychological warfare, brutally killing anyone who dared to oppose them, including women and children. This frightened many nobles into simply submitting and paying tribute instead of allowing their lands to be devastated.
In the field, Europeans (especially Hungarians and Poles) quickly learned that usual medieval infantry armed with pikes doesn't stand chance in open terrain. Mongols would not charge them, but simply encircle them and shower with arrows until they break. Then would pursue and slaughter them. Light cavalry was also no match because they didn't have weapons effective as Mongolian bow. Only heavily armored knights did well if their horses were rested enough so they could catch up with Mongols, but if Mongols retreated (their usual tactics) and then attacked again, knight's horses would be tired and even they would be defeated. One example of such battle is Battle of Mohi.
Mongols were able to successfully overcome usual fortifications made of wood and earth, but stone fortifications coupled with crossbowman were tougher nut to crack. They didn't have time for lengthy sieges that would starve out such fortifications, and could not build heavier siege equipment to overcome them. Prime example would be Siege of Esztergom, where city itself was taken by Mongols, but stone citadel was not. After this, Hungarians started to build similar forts across their lands, and in further Mongol raids evacuated population and supplies into them, burning everything they could not carry to prevent it falling into Mongol hands. As Mongols traveled lightly, hoping to live of the land they were attacking, this hindered them greatly.
Another tactic, favored by Bulgarians and Serbs, was to simply attack Mongols in unfavorable terrain. Their part of Europe is full of mountains, forests and narrow roads. Mongols could not employ their light cavalry effectively there, and opponents could get to range where they would negate advantage of Mongolian bows.
In second Mongol invasion of Hungary these elements came together. Mongols were allowed to roam countryside, but most of it was already devastated (scorched earth tactic) . They could not take stone fortifications, and as they divided their forces to loot, smaller detachments were defeated by now much expanded Hungarian heavy cavalry. Finally, weakened main army was defeated and routed in the hills of western Transylvania, unfavorable terrain for Mongols.
It is worth mentioning that descendants of Mongols (Golden Horde and Crimean Tatars) remained a threat and burden for Russia much longer. They were finally defeated and eliminated much latter, with the advent of better firearms that could negate their mastery with bow and arrow. One distinctively Russian invention for fight against Mongolian (Tatar) cavalry in the open was Gulay-gorod, type of mobile fortification that shielded troops behind from arrows and allowed them to employ their firearms.