The north-west of the Indian subcontinent - today mostly Pakistan - was in ancient times very much connected to the Iranian world across the mountains. Its Indo-european speaking people were closely related to the Iranians, and probably once formed a single Indo-Iranian grouping before the Iranians drifted westwards and the Indians to the south. Although before the Indo-european speakers arrived, there had been a highly sophisticated civilisation that had lasted for two millennia:
Early history: the Indus Valley civilisation
The Indus valley between 3,300 BC and 1500 BC was home to a flourishing civilisation, comparable with its contemporaries in Mesoptamia and Egypt (though bigger than either). By the Bronze Age the Harappa or Indus Valley civilisation (which included the great complex at Mohenjo-Daro) supported numerous large cities (up to a mile square, with tens of thousands of inhabitants), and a total population of maybe 5 million. They had writing (though it's not been deciphered) and practised a religion seen by some as the precursor of Hinduism. Their houses had bathrooms, and their streets were laid out on a grid system, with advanced sewage systems. There were no huge palaces, indicating a political organisation probably not based on monarchy, and women seem to have had an honoured if not equal position in society. Europe would not catch up for millennia. Their civilisation, though, began to fade away from around 2000 BC, a victim, most probably, of climate change. They were superseded from around 1500 BC by people from the north (speaking an Indo-european language, and related to the Iranians - and sometimes called Aryans) who were nomadic herders, with no cities, no writing: it was a long time before they approached the same level of civilisation as their Harappan predecessors.
Darius I boasts of his empire extending:
From the Saka beyond Sogdia to Nubia, and from India to Lydia.
Details are scarce: Herodotus has a tantalising snippet about the sea-route. It eventually extended to include the whole Indus valley - and according to Herodotus again, became the wealthiest and most populous part of the empire.
The number of Indians is greater than any other peoples we know of and they brought in more tribute than the others - 360 talents of gold dust; this being the twentieth satrapy. Adding it all up, the yearly total comes to 14,560 talents. The king stores the tribute like this: he pours the molten metal into earthenware jars; when they are full he breaks the outside layer.
It comprised two satrapies: Gandhara (north) and India (south). Indian contingents fought in Xerxes' army as well as later against Alexander.
Alexander in India
Achaemenid influence in India had declined considerably by the time Alexander crossed through the Khyber Pass in 326 BC. He was not content with eliminating the Achaemenid presence: his army marched on. His main opponent was Porus (the Greek version of his name) king of the Paurava, who he defeated at the Battle of the Hydaspes (the Jhelum; one of the five rivers of the Punjab): the hardest battle he ever fought, and where Porus emerged with such credit that he was kept in power as a client-king. It was the first time Europeans faced war-elephants in battle. Alexander had intended to carry on eastwards, but when his army mutinied at the thought, he was forced to reconsider, making his way back towards Babylon, fighting all the way down the Indus valley (and getting seriously wounded in one attack). He left behind an administration of sorts.
In the chaos following Alexander's death, Porus was soon murdered (217 BC) and the Macedonians left India to join in the competition for the spoils. Alexander's destruction of the many small kingdoms (and republics, interestingly) left a vacuum that was soon to be filled by Chandragupta, founder of the Maurya empire, who for the first time unified most of the subcontinent (322 - 298 BC). Seleucus decided he would not win a war to recover Alexander's Indian empire, and made a deal. Chandragupta would keep the territory he'd won on the west of the Hindu Kush (Arachosia: the region which later became Seistan) as well as being unchallenged in India itself: in return Seleucus would receive a number of elephants (400-500?). These elephants helped swing the vital Battle of Ipsus in his favour a few years later in 301 BC. Greek writers' knowledge of India under Chandragupta (Sandrakottos in Greek) was boosted by Megasthenes, a Greek traveller who was a sort of ambassador for Seleucus in the Maurya court at Pataliputra. His book Indika survives in fragments; it was the source of many ludicrous tales, but also some useful information. An extract:
India has many huge mountains which abound in fruit-trees of every kind, and many vast plains of great fertility - more or less beautiful, but all alike intersected by a multitude of rivers.
The greater part of the soil, moreover, is under irrigation, and consequently bears two crops in the course of the year. It teems at the same time with animals of all sorts, - beasts of the field and fowls of the air, - of all different degrees of strength and size. It is prolific, besides, in elephants, which are of monstrous bulk, as its soil supplies food in unsparing profusion, making these animals far to exceed in strength those that are bred in Libya. It results also that, since they are caught in great numbers by the Indians and trained for war, they are of great moment in turning the scale of victory.
Famously, he also describes the Indian caste system. Read text of his surviving fragments here:
The Indo-Greeks: Menander
Antiochus III failed to end Bactria's independence, but he did recover the Seistan area (Arachosia). The Maurya empire reached its zenith under Asoka the Great (304 -232 BC) - who became a patron of Buddhism in remorse after a cruel victory over the Kalinga. He's widely admired as one of the greatest rulers in world history. But within 50 years of his death, the Maurya empire was disintegrating. The northwestern part was soon (in 190 BC) picked off by the Bactrian Greeks. Two families, descendants of rival factions back in Bactria, competed for control of the wealthy new Indian possessions - but both had to give way to a third contender, whose origin is obscure: Menander I (c155 - 130 BC). His coins (the commonest in Greek India) would indicate that he was a powerful and long-lived ruler, though very little is certain. He appears in an Indian work ("The Questions of Milinda" - ie Menander - a sort of Platonic dialogue) as an enthusiastic student of Buddhism. His successors fully embraced Buddhism. But despite or because of his Indian successes, he could not hold on to his Bactrian base, which was lost to the Kushans during his watch. The last Greek king in India (Strato II), presumably a descendant, ruled in the eastern Punjab until maybe AD 10. If you want to know the finer details of the Greek rule in India, there is a table in Wikipedia, complete with coin-portraits of all the Indo-Greek kings.
Later Iran-India contact
Under the Parthians, trade by sea with India flourished, and continued to do so under the Sasanians. The holy man Mani travelled to India, and so did Christian missionaries of the Church of the East - as far as Sri Lanka, in fact. India also acted as a middleman for trade further east - for Chinese silk: part of a well-established sea-route between China and Iran, rivalling the overland silk route. Spices, perfumes, precious stones, pearls all found their way into the Roman empire via Iranian intermediaries. A Greek guidebook to the ports from the Red Sea to India (c.AD 50) includes passages like this:
There are imported into this market-town (Barigaza, now Bharuch in NW India), wine, Italian preferred, copper, tin, and lead; coral and topaz; thin clothing and inferior sorts of all kinds; bright-colored girdles a cubit wide; storax, sweet clover, flint glass, realgar, antimony, gold and silver coin, on which there is a profit when exchanged for the money of the country; and ointment, but not very costly and not much. And for the King there are brought into those places very costly vessels of silver, singing boys, beautiful maidens for the harem, fine wines, thin clothing of the finest weaves, and the choicest ointments. There are exported from these places spikenard, costus, bdellium, ivory, agate and carnelian, lycium, cotton cloth of all kinds, silk cloth, mallow cloth, yarn, long pepper and such other things as are brought here from the various market-towns. Periplus of the Erythraean Sea 49
In the 16th century, a great-grandson of Timur (also directly descended from Genghis through his mother), Zahid ud-Din Muhammad, known as Babur ("The Tiger"), ousted from his family's territory in Fergana,Transoxiana, invaded India, where he founded the dynasty known as the Mughals (whose name derives from "Mongols"). His successors included Akbar (1542-1605), Shah Jahan (1592-1666, who built the Taj Mahal for his wife Mumtaz) and Aurangzeb (1618-1707). The Mughals' decline began with the death of Aurangzeb, and became terminal after the invasion of Nader Shah (1738). Their lands were divided, the British East India Company moved in. The last Mughal, Bahadur Shah, know as Zafar, died in exile in Rangoon in 1862.Despite their Mongol-Turkic heritage, the Mughals adopted Persian as their the official language. It was the language normally spoken at court, though Arabic was used in Islamic contexts. Persian was the main language for Mughal literature.
Babur on a rhinoceros hunt