Anandpur was besieged repeatedly between 1700 and 1704, first by the hill rajas and then by imperial forces under the governors of Sirhind and Lahore acting on Aurangzeb's orders.
The forts around the town, Anandgarh, Keshgarh, Lohgarh, Fatehgarh and Holgarh, were built and held during this period. The Sikhs sallied repeatedly. Bhai Bachittar Singh Ji's action against a drunken elephant sent to break the Lohgarh gate is one of the best known episodes.
The last siege ran through most of 1704 and reduced the garrison to eating bark and leaves. Forty Singhs of the Majha left, signing a disclaimer, and returned the following year to die at Khidrana.
In December 1704 an oath was sworn on the Qur'an and on the cow that the party would be allowed to leave unmolested. The Guru did not believe it and left anyway, on the insistence of those with him. The oath was broken at the Sarsa in flood.
The family was scattered at that crossing. Two sons died at Chamkaur within days and two at Sirhind within the fortnight. The Zafarnama is the Guru's letter to Aurangzeb about the broken oath.
The town was besieged more than once, by hill state forces and by Mughal troops together, and the final siege in 1704 lasted months and ended in a negotiated evacuation.
The assurances given for that evacuation were broken as soon as the column left, and the pursuit began at the Sarsa the same night.
Everything that follows, Chamkaur, Machhiwara, Sirhind, Muktsar and the Zafarnama, comes out of that broken assurance, and the Zafarnama says so directly.