The area around Gujrat was settled during the reign of the Suri ruler Sher Shah prior the Mughals.
The area was named Khwaspur, in honour of Suri's Governor of Rohtas, Khwas Khan.
Local traditions state that Gujrat is the second town to be built in the area, with the first having been destroyed by Mongol invasions in 1303.

The city came under the Mughal Empire and was further developed during the reign of the Mughal Emperor Akbar, who built the Gujrat Fort in 1580, and compelled local Gujjars to settle in the city in 1596–97.
The city was then named in reference to the Gujjar tribes.
In 1605, Syed Abdul Kasim was granted the city as a fief by Akbar.

During the reign of Emperor Jahangir, Gujrat was part of the route used by Mughal royals when visiting Kashmir.

Legend has it that the most famous saint of Gujrat, Shah Daula, is credited with having saved the city from the Sikh Guru Hargobind when the people of Gujrat made fun out of him during his stay as he was returning from Kashmir around 1620.

During the Mughal era, Gujrat was encircled by a wall with five gates, of which only the Shah Daula gate survives.

With the death of Aurangzeb in 1707, the Mughal Empire began to weaken significantly.
The authority which did linger on remained in the hands of Mughal Nawabs who gave nominal allegiance to the Mughal emperor in Delhi.
However in 1739, the powerful Turko-Iranian ruler Nader Shah gave the Mughals the final blow when he launched a plundering invasion sacking their capital Delhi.
During his campaign, Nadir Shah sacked Gujrat on the way which was at the time a prosperous city.
Shortly afterwards around 1741, the city was captured by local Punjabi Gakhar tribesmen in the ensuing chaos from near the Rawalpindi area.
The city suffered further from the eight invasions of the Durrani Afghans under their new energetic ruler Ahmad Shah Durrani between 1748 and 1767.

In 1765, the city was overrun by the Sikh Bhangi Misl under Gujjar Singh who defeated the Punjabi Ghakars under Muqqarab Khan.
The Sikhs defeated an Afghan force in a battle for Gujrat on 29 April 1797.
In 1798, the Bhangi leader Sahib Singh pledged allegiance to the Sukerchakia Misl of Ranjit Singh who later established the Sikh Empire in 1799.
By 1810, Ranjit Singh's armies captured the city from Bhangi forces, thereby extending the rule of the Sikh Empire to the city.

Gujrat finally came under British control in 1849, following the collapse of the Sikh Empire in the wake of the Sikh defeat at the Battle of Gujrat on 22 February, which ended the Second Anglo-Sikh War.
In 1867, Gujrat was constituted as a municipality.
The area around Gujrat was settled during the reign of the Suri ruler Sher Shah prior the Mughals. The area was named Khwaspur, in honour of Suri's Governor of Rohtas, Khwas Khan. Local traditions state that Gujrat is the second town to be built in the area, with the first having been destroyed by Mongol invasions in 1303.
The city came under the Mughal Empire and was further developed during the reign of the Mughal Emperor Akbar, who built the Gujrat Fort in 1580, and compelled local Gujjars to settle in the city in 1596–97. The city was then named in reference to the Gujjar tribes. In 1605, Syed Abdul Kasim was granted the city as a fief by Akbar.
During the reign of Emperor Jahangir, Gujrat was part of the route used by Mughal royals when visiting Kashmir.
Legend has it that the most famous saint of Gujrat, Shah Daula, is credited with having saved the city from the Sikh Guru Hargobind when the people of Gujrat made fun out of him during his stay as he was returning from Kashmir around 1620.
During the Mughal era, Gujrat was encircled by a wall with five gates, of which only the Shah Daula gate survives.
With the death of Aurangzeb in 1707, the Mughal Empire began to weaken significantly. The authority which did linger on remained in the hands of Mughal Nawabs who gave nominal allegiance to the Mughal emperor in Delhi. However in 1739, the powerful Turko-Iranian ruler Nader Shah gave the Mughals the final blow when he launched a plundering invasion sacking their capital Delhi. During his campaign, Nadir Shah sacked Gujrat on the way which was at the time a prosperous city. Shortly afterwards around 1741, the city was captured by local Punjabi Gakhar tribesmen in the ensuing chaos from near the Rawalpindi area. The city suffered further from the eight invasions of the Durrani Afghans under their new energetic ruler Ahmad Shah Durrani between 1748 and 1767.
In 1765, the city was overrun by the Sikh Bhangi Misl under Gujjar Singh who defeated the Punjabi Ghakars under Muqqarab Khan. The Sikhs defeated an Afghan force in a battle for Gujrat on 29 April 1797. In 1798, the Bhangi leader Sahib Singh pledged allegiance to the Sukerchakia Misl of Ranjit Singh who later established the Sikh Empire in 1799. By 1810, Ranjit Singh's armies captured the city from Bhangi forces, thereby extending the rule of the Sikh Empire to the city.
Gujrat finally came under British control in 1849, following the collapse of the Sikh Empire in the wake of the Sikh defeat at the Battle of Gujrat on 22 February, which ended the Second Anglo-Sikh War. In 1867, Gujrat was constituted as a municipality.
Gujrat, Pakistan