Starting in the 400s AD, Turkic and Mongol people had been expanding out of the northern part of Central Asia. They spread all over Europe and Asia. The Huns came first, then the Avars, the Ghaznavids, and the Seljuks. About 1000 AD, the Turkish Ghaznavids invaded northern India from what is now Afghanistan. India was so rich that the Ghaznavids got a lot of plunder – gold and pearls. They also took a lot of Indian people and enslaved them. But by 1040, the Seljuks took power from the Ghaznavids, and the Seljuks took no interest in India. They just left it alone.
A century and a half later, in 1192 AD, there was a new group of Turkic invaders, the Mamluks. They invaded northern India and established the Delhi Sultanate, ruling northern India. Under the Delhi Sultanate, many people in northern India converted to Islam.
By the early 1200s, the Mongols, under their king Genghis Khan, were conquering and uniting all of Asia. They conquered the Uighurs, the Kyrgyz, and the Khitan, and made them into one big empire stretching from Mongolia to Russia. In 1221 AD, that Turkic/Mongol expansion reached India for the first time. Genghis Khan sent his Mongol troops riding down from Iran and Afghanistan into India. Genghis Khan’s son Ogedei ruled after him, and then his grandson Mongke. By 1235, these men ruled what is now Pakistan and Kashmir, in northern India. When Indian states got into wars, they started to ask the Mongol army for help. Soon the Mongols were the main power in all of northern India. But they didn’t entirely take over the Delhi Sultanate. They had enough problems with their huge empire already.
By about 1300, the Mongols got weaker and the Delhi Sultanate got stronger under the new Khalji Dynasty. So the Delhi Sultanate won several big battles and pushed the Mongols out of India.
The Mongols invaded India once again in 1398. An unrelated Mongol khan, Timur, was trying to rebuild the Mongol empire. Timur got as far as Delhi and sacked the city. (He wrecked and plundered it.) That ended the Delhi Sultanate. The collapse left nobody in charge. But soon there was yet another Mongol invasion – by a descendant of Timur’s. He established the Mughal Empire.