Virata rules the kingdom of Matsya, and his court becomes the setting for one full book of the Mahabharata, the Virata Parva, because of the terms of the Pandavas' exile: having lost a rigged game of dice to their cousin Duryodhana, Yudhishthira and his brothers agreed to spend twelve years in the forest followed by a thirteenth year living completely undetected, on pain of resuming a further twelve years if discovered.
The five brothers and their shared wife Draupadi choose Virata's kingdom for this final, hardest year and enter his service in disguise: Yudhishthira as a courtier and dice player, Bhima as a cook, Arjuna as a eunuch dance instructor to the princess Uttara, Nakula and Sahadeva as a horse keeper and cowherd, and Draupadi as a queen's attendant. Virata himself never recognizes any of them for who they are through most of the book, and the drama of the Virata Parva turns on a series of near discoveries, culminating in Bhima's killing of Virata's brother-in-law Kichaka after Kichaka harasses Draupadi, an act the disguised Pandavas must explain away without exposing themselves. Virata's court, drawn into events far beyond its own ordinary politics, functions in the epic as the last testing ground of the Pandavas' patience and self control before they can openly reclaim their kingdom.