Shalya is the brother of Madri, and thus the uncle of the younger Pandava twins Sahadeva and Nakula, and was the the king of Madra (modern-day Punjab, Pakistan). A clever man with a sharp and calm mind, he first showed his wits by intercepting King Pandu and his retinue on their return to the capital of Hastinapur, where he proposed that they settled their differences through either single combat between their generals or marriage. Pandu was impressed with the heavily-armored but small general, and decided to represent himself in combat, fancying his chances against someone so physically inferior. However, when the time came for their battle, the general stripped their armor and revealed themselves to be Madri, whose beauty instantly charmed Pandu, and so the differences of their royal houses was settled by marriage instead.
Once his twin nephews turned of age, he invited them to his court, and asked for them to become his heirs, having no sons of his own, and promised them both to be crown princes of Madra instead of fourth in line for the throne of Pandu’s kingdom of Kuru. Sahadeva and Nakula at first believed their uncle to be deceiving them for political gain, thinking he simply wanted demigods for heirs, and when they confront him with this, they are shocked to learn that he’s genuine. Unlike many kings, he married for love, and mourned his own wife’s infertility, simply hoping that they would carry on their family’s legacy as his surrogate sons. Touched by his genuine plea, Sahadeva and Nakula agree on the condition that they will stay with their family until Shalya’s death, to which their uncle agrees.
When the word of the impending conflict at Kurukshetra spread, Shalya was among the first to march forth to join his nephews. On his way, however, he encounters a large army camp which has prepared a great feast and many forms of entertainment for his arrival, of which Shalya and his forces partake, partying far into the night. Shalya, impressed by the great generosity and very intoxicated, offers to swear an oath for the host, who reveals himself to be Duryodhana with his advisor Shakuni, rather than Yudhisthira, as Shalya had predicted. Shalya, true to his word however, reluctantly does not go back on his word, and swears fealty to Duryodhana. The very next day, with the festivities over, Shalya rides ahead of his army to inform his nephews of the mistake, and though they are furious, they are ultimately made to be understanding by Yudhisthira, having all been victims of similar trickery. Sharing one last hug as uncle and nephews, Shalya departs in tears.
On the battlefield at Kurukshetra, Shalya fights valiantly, defeating and killing the king and princes of the kingdom of Matsya, who had all generously hosted the Pandavas in disguise during their exile, and though he praises them all as valiant warriors, the hatred of his nephews towards him only grows as a result. Though he had spared his nephews a true onslaught by refusing to serve as anyone’s charioteer, his actions in battle had only bittered his relationship with them, and so to regain their trust, Shalya decides to help them as best he can when the opportunity strikes.
After the death of Drona, Karna takes up leadership of the Kaurava forces, and Shalya volunteers as his charioteer, which Karna accepts, seeing at once though his intent. Shalya serves Karna dutifully as a charioteer, scattering the Pandava forces wherever their chariot went, but all the while, Shalya attempts to demoralize Karna by insulting him, praising his enemies and giving him incorrect advice, though the virtuous Hero of Charity is unfazed. This impresses Shalya, looking on in awe as the warrior shone like the sun even when bombarded with insults and enemy arrows, but out of duty he persists even as his insults are ineffective.
This continues for two days until Karna and Shalya charge into battle against the latter’s twin nephews and Shalya, terrified for their lives, begs them to flee. Furious at their uncle and the man who had defeated them long ago in the martial exhibition their family had arranged when they were still in power, they stand their ground, and are soundly defeated in a short span of time. Shalya, having ridden their chariot with his eyes closed to not have to see his nephews be massacred, is asked to open his eyes by Karna, and sees that though the two are wounded and their weapons scattered all over the field, the hero of Charity has spared his nephews, and commands Shalya to ride back to camp. So ashamed of his conduct towards Karna, Shalya begs for his forgiveness and ceases his childish way of helping his nephews.
The next day, Karna has his titanic clash with Arjuna, his own prowess, myriad of powerful weapons and Shalya’s flawless driving skills allowing him to gain the upper hand against the Pandava and his godly charioteer, despite all odds. All the many curses Karna had been afflicted with struck him at once, robbing him of a majority of his Astras, causing his bow arm to seize up, and the earth itself went muddy and forcefully seized his chariot’s wheels. Terrified of Aruna’s furious gaze upon the two as they struggled to pull the chariot free of the earth goddess’ grasp, Shalya fled ungracefully, so terrified he didn’t look back until he heard Karna’s head be scooped from his shoulders by Arjuna’s Anjilikastra.
When he returned to the Kaurava camp, Shalya’s senses finally returned to him, and so overcome by grief and shame, he volunteers to lead the Kaurava in the place of the man he had led down, going into No Man’s Land to retrieve Karna’s banner in the middle of the night and leaving his crown as the king of Madra in the spot where Karna’s head had fallen as an offering. His impassioned charge on the next and final day of the war was so valiant that it rallied the Kaurava forces on the brink of retreat, and though he is ultimately defeated by Yudhisthira in a duel of spears, he sells his life dearly.
True to his word, Nakula succeeds his uncle as King of Madra in the aftermath of the war, until the Pandavas leave for the Himalayas.