The Sikh Rule in Lahore initiated from the invasion and rule of the Sikh Misls and extended till the Sikh Empire of Ranjit Singh (also known as Punjab, the Sikh Raj, and Sarkar Khālsā Rāj) which ended in 1849. The Sikhs began gaining power following the decline of the Mughal Empire in Punjab and consisted of a collection of autonomous Punjabi Misls, which were governed by Misldars, mainly in the Punjab region.
Early in Aurangzeb's reign, various insurgent groups of Sikhs engaged Mughal troops in increasingly bloody battles. In 1670, the ninth Sikh Guru, Guru Tegh Bahadur encamped in Delhi, receiving large numbers of followers, was said to have attracted the wrath of Emperor Aurangzeb.
The execution of Guru Tegh Bahadur infuriated the Sikhs. In response, his son and successor, the tenth Guru of Sikhism Guru Gobind Singh further militarized his followers.
The Khalsa, or the Sikh Army, were the first in history to abolish the Muslim states and Mughal Empire in the whole province of Punjab in one stroke. The Singhs (Lions), led by Banda Singh Bahadur took over many Muslim and Mughal lands, establishing a Sikh Empire.
Other existing Muslim Emperors proclaimed a war against the Banda and the Khalsa. However many Muslim armies and their Emperors fled in dismay and despair after Wazir Khan's head was stuck up on a spear and lifted high up by a Sikh who took his seat at Sirhind, Muslim troops on beholding the head took alarm.
In a temporary alliance, both groups consisting of Hindu Rajas and Muslim Governors attacked Guru Gobind Singh and his followers. The united Mughal-Rajput Imperial alliance laid siege to the fort at Anandpur Sahib. In an attempt to dislodge the Sikhs, Aurangzeb promised that the Guru and his Sikhs would be allowed to leave Anandpur safely. He is said to have validated this promise in writing. However, he deliberately failed to keep his promise and when the remaining few Sikhs were leaving the fort under the cover of darkness, the Mughals were alerted and engaged them in battle once again. Two of the younger sons of Guru Gobind Singh, Zoravar Singh and Fateh Singh, were bricked up alive within a wall by Wazir Khan in Sirhind (Punjab). The other two elder sons - Ajit Singh and Jujhar Singh along with several Sikhs fought against the giant Mughal force, achieving martyrdom. The Emperor died shortly after on 20 February 1707. He was succeeded by Bahādur Shāh, who invited the Gurū to a meeting which took place at Āgrā on 23 July 1707.