William and Kate were given a tour of the holy site in Lahore on the fourth day of their royal tour of Pakistan.
Walking in with Imam Abdul Kabir Azad and the Honorary Consul to the UK Fakir Aijazuddin, the duchess had bare feet, while the duke wore socks with his cream linen suit.
The late Diana visited the religious site in 1991, on one of her visits to the Islamic country.
It was also included in the 2006 royal tour of the Prince of Wales and the Duchess of Cornwall.
William and Kate walked on a red carpet through the holy building with the imam before being given a tour of the inside, where they heard a Koranic verse.
The couple were invited to sit down cross-legged after being introduced to a group of scholars and religious leaders, who were sitting on cushions, for a discussion on promoting interfaith harmony among communities.
Among the group was Dr Ayesha Leghari, a Sunni Muslim scholar, who explained the verse to them.
“I was telling then how it is compulsory for us to respect other religions,” Dr Leghari told reporters afterwards.
She added that the couple were “charming” and interested and engaged in the discussion.
When William and Kate left the mosque, they were told by Mr Aijazuddin: “If there’s one word to describe your visit, it is joy. You have radiated joy wherever you have been.”
The duke replied: “We are very happy people.”
Earlier yesterday, the couple both took turns at the crease in a game of cricket at the National Cricket Academy in Lahore.
The competitive couple both spent some time at the wicket before high-fiving the young boys and girls they had been playing with.
They joined children participating in the British Council’s Dosti programme and were introduced to a number of cricketing figures at the ground, including Waqar Younis, former fast bowler for Pakistan.
Their first stop on the fourth day of their tour was a trip to the SOS Children’s Village, where they attended a birthday party.
The duchess made her first speech of the week at the charitable organisation, which provides a home for some 150 orphaned young boys and girls.