Har Rai was born to Nihal Kaur and Baba Gurditta into a Sodhi household. His father died while he was 8 years old. At age 10, in 1640, Guru Har Rai was married to Mata Kishan Kaur (sometimes also referred to as Sulakhni) the daughter of Daya Ram. They had two children, Ram Rai and Har Krishan, the latter of whom became the eighth Guru.
After Aurangzeb won the succession war in 1658, he summoned Guru Har Rai in 1660 to explain his support for the executed Dara Shikoh. Har Rai sent his elder son Ram Rai to represent him. Aurangzeb kept Ram Rai as hostage, questioned Ram Rai about a verse in the Adi Granth – the holy text of Sikhs at that time. Aurangzeb claimed that it disparaged the Muslims. Ram Rai changed the verse to appease Aurangzeb instead of standing by the Sikh scripture, an act for which Guru Har Rai is remembered for excommunicating his elder son, and nominating his younger son Har Krishan to succeed him. Har Krishan became the eighth Guru at age 5 after Guru Har Rai's death in 1661. Some Sikh literature spell his name as Hari Rai.
Guru Har Rai provided medical care to Dara Shikoh, possibly when he had been poisoned by Mughal operatives. According to Mughal records, Har Rai provided other forms of support to Dara Shikoh as he and his brother Aurangzeb battled for rights to succession. Ultimately, Aurangzeb won, arrested Dara Shikoh and executed him on charges of apostasy from Islam. In 1660, Aurangzeb summoned Har Rai to appear before him to explain his relationship with Dara Shikoh.
The organizational structure that had helped Sikhs to grow and resist the Mughal persecution had created new problems for Guru Har Rai. The donation Collectors, some of the Masands (local congregational leaders) led by Dhir Mal – the older brother of Guru Har Rai, all of them encouraged by the support of Shah Jahan, land grants and Mughal administration, had attempted to internally split the Sikhs into competing movements, start a parallel guruship, and thereby weaken the Sikh religion. Thus a part of the challenge for Guru Har Rai was to keep Sikhs united.
Authentic literature about Guru Har Rai life and times are scarce, he left no texts of his own and some Sikh texts composed later spell his name as "Hari Rai". Some of the biographies of Guru Har Rai written in the 18th century such as by Kesar Singh Chhibber, and the 19th century Sikh literature are highly inconsistent.