Capable of accommodating 10,000 worshippers in its main prayer hall and 100,000 in its courtyard and porticoes, it remained the largest mosque in the world from 1673 to 1986 (a period of 313 years), when overtaken in size by the completion of the Faisal Mosque in Islamabad. Today, it remains the second largest mosque in Pakistan and South Asia and the fifth largest mosque in the world after the Masjid al-Haram (Grand Mosque) of Mecca, the Al-Masjid al-Nabawi (Prophet's Mosque) in Medina, the Hassan II Mosque in Casablanca and the Faisal Mosque in Islamabad.
To appreciate its large size, the four minarets of the Badshahi Mosque are 13.9 ft (4.2 m) taller than those of the Taj Mahal and the main platform of the Taj Mahal can fit inside the 278,784 sq ft (25,899.9 m2) courtyard of the Badshahi Mosque, which is the largest mosque courtyard in the world.
Construction of the Badshahi Mosque was ordered in May 1671 by the sixth Mughal Emperor, Aurangzeb, who assumed the title 'Alamgir'. Construction took about two years and was completed in April 1673. The construction work was carried out under the supervision of Aurangzeb's foster brother Muzaffar Hussain (also known as Fidaie Khan Koka) who was appointed Governor of Lahore in May 1671 and held this post until 1675. He was also Master of Ordnance to the Emperor. The mosque was built opposite the Lahore Fort, illustrating its stature in the Mughal Empire. In conjunction with the building of the mosque, a new gate was built at the Fort, named Alamgiri Gate after the Emperor.
When the British took control of India, they would use the mosque for their military purposes by using the mosque for gun practices, cannons, etc. Even though they sensed Muslim hate for the British, they demolished a large portion of the wall of the mosque so the Muslims could not use it as a kind of "fort" for anti-British reasons. After a while, they finally returned it to the Muslims as a good will gesture, even though it was in terrible condition. It was then given to Badshahi Mosque Authority to restore it to its original glory.
From 1852 onwards, piecemeal repairs were carried out under the supervision of the Badshahi Mosque Authority. Extensive repairs were carried out from 1939 to 1960 at a cost of about 4.8 million rupees, which brought the mosque to its original shape and condition. The blueprint for the repairs was prepared by the late architect Nawab Zen Yar Jang Bahadur.
On the occasion of the second Islamic Summit held at Lahore on February 22, 1974, thirty-nine heads of Muslim states offered their Friday prayers in the Badshahi Masjid, led by Mawlānā Abdul Qadir Azad, the Khatib of the mosque.
A small museum is also attached to the mosque complex. It contains relics of the Prophet Muhammad, his cousin Ali, and his daughter, Fatimah.
In 2000, the marble inlay in the main vault was repaired under the supervision of Saleem Anjum Qureshi. In 2008, replacement work began to be carried out on the red sandstone tiles on the mosque's large courtyard, using red sandstone especially imported from the original source in Rajasthan, India.
Badshahi Mosque was somewhat damaged and misused during the glorious reign of Maharaja Ranjit Singh, some claim it was converted into a stable for his horses,other sources say it was used as a gun powder magazine for military stores. However, these claims can be dismissed as historical fallacies. During Maharaja Ranjit Singh's reign, Muslims were not allowed to enter the mosque to pray; they were only given a small place outside the mosque where they could worship.