According to Sikh tradition based on an old Punjabi manuscript Panjah Sakhian, Samarth Ramdas met Guru Hargobind (1595-1644) at Srinagar in the Garhval hills. The meeting, corroborated in a Marathi source, Ramdas Swami`s Bakhar, by Hanumant Swami, written in 1793, probably took place in the early 1630`s during Samarth Ramdas's pilgrimage travels in the north and Guru Hargobind`s journey to Nanakmata in the east. It is said that as they came face to face with each other, Guru Hargobind had just returned from a hunting excursion. He was fully armed and rode a horse. "I had heard that you occupied the Gaddi of Guru Nanak", said the Maratha saint Ramdas, and asked what sort of sadhu was he. Guru Hargobind replied, "Internally a hermit, and externally a Prince. Arms mean protection to the poor and destruction of the tyrant. Baba Nanak had not renounced the world but had renounced Maya".
On 25 May 1606 Guru Arjan nominated Hargobind as his successor and instructed his son to start a military tradition to protect the Sikh people and always keep himself surrounded by armed Sikhs for protection. Shortly afterwards, Guru Arjan was arrested, tortured and killed by order of the Mughal Emperor Jahangir, Guru Hargobind's succession ceremony took place on 24 June 1606. He put on two swords: one indicated his spiritual authority (piri) and the other, his temporal authority (miri). He followed his martyred father's advice and always kept himself surrounded by armed Sikhs for protection. The number fifty two was special in his life, and his retinue consisted of fifty two armed men. He thus founded the military tradition in the Sikh faith.
Jahangir responded by jailing the 14 year old Guru Hargobind at Gwalior Fort in 1609, on the pretext that the fine imposed on Guru Arjan had not been paid by the Sikhs and Guru Hargobind. It is not clear as to how much time he spent as a prisoner. The year of his release appears to have been either 1611 or 1612, when Guru Hargobind was about 16 years old. Persian records, such as Dabistan i Mazahib suggest he was kept in jail for twelve years, including over 1617-1619 in Gwalior, after which he and his camp were kept under Muslim army's surveillance by Jahangir.
It is unclear why he was released. Scholars suggest that Jahangir had more or less reverted to tolerant policies of Akbar by about 1611 after he felt secure about his throne, and the Sunnis and Naqshbandhi court officials at the Mughal court had fallen out of his favour. Another theory states that Jahangir discovered the circumstances and felt Guru Hargobind was harmless, so he ordered his release.
During the reign of Shah Jahan that started in 1627, relations became bitter again. Shah Jahan was intolerant. He destroyed the Sikh baoli at Lahore. In 1628, Shah Jahan's hunting party plundered some of Guru Hargobind's property, which triggered the first armed conflict.
Guru Hargobind's army fought battles with the Mughal armies of Shah Jahan at Amritsar, Kartarpur and elsewhere. Guru Hargobind defeated the Mughal troops near Amritsar in the Battle of Amritsar in 1634. The Guru was again attacked by a provincial detachment of Mughals, but the attackers were routed and their Leaders slain. Guru Hargobind also led his armies against the provincial Muslim governors. The Guru anticipated the return of a larger Mughal force, so retreated into Shivalik Hills to strengthen his defenses and army, with a base in Kiratpur where he continued to stay till his death.
Shah Jahan attempted political means to undermine the Sikh tradition, by dividing and influencing the succession. The Mughal ruler gave land grants to Dhir Mal, living in Kartarpur, and attempted to encourage Sikhs to recognise Dhir Mal as the rightful successor to Guru Hargobind. Dhir Mal issued statements in favour of the Mughal state, and critical of his grandfather. Guru Hargobind died at Kiratpur Rupnagar, Punjab, on 19 March 1644, but before his death he rejected Dhir Mal and nominated Har Rai instead to succeed him as the Guru.