Four Pakistanis, an Indian and a police officer were among those killed in the gun attack, according to Pakistani, Indian and Omani officials.
The Oman police said 28 people of various nationalities were wounded, including security personnel.
A video on social media verified by Reuters showed people running away from the mosque while gunshots could be heard.
Police have not said whether they have identified a motive for the attack or if they had made any arrests.
The identity of the attackers has also not been released.
Pakistan's foreign ministry said the attack took place at the Ali bin Abi Talib mosque.
A local source said it was also known as Imam Ali mosque, a Shi'ite place of worship in Ibadi-ruled Oman, which has a small but influential Shi'ite minority.
My deepest condolences and heartfelt sympathies to the families of four Pakistani nationals who were killed in the dastardly terrorist attack on Imam Bargah Ali bin Abu Talib in Muscat, Oman. Strongly condemn this cowardly attack and killing of Muslims in the holy month of…— Ishaq Dar (@MIshaqDar50) July 16, 2024
Describing the incident in the Wadi al-Kabir district of Oman's capital Muscat as a "terrorist" attack, the Pakistani ministry said 30 survivors were being treated in hospitals.
The attack came as Shi'ite Muslims observed Ashura, an annual period of mourning to commemorate the 7th century death of Hussein, a grandson of the Prophet Mohammed.
The observation of Ashura has sometimes triggered sectarian tensions between Sunni and Shi'ite Muslims in some Middle East countries although not typically in Oman where the Ibadi sect promotes tolerance.
Most Omanis adhere to the Ibadi faith, which is a branch of Islam that has much in common with mainstream Sunni Islam.
"This is a very unprecedented event... the likes of it we have not seen in Oman's history," Pakistani ambassador to Muscat Imran Ali said, expressing gratitude to law enforcement and hospital staff.
The ambassador earlier visited some victims in hospital.
He said most of the 30 victims there were being treated for gunshot wounds while others had suffered injuries fleeing the attack, including being crushed in the stampede.
Some Pakistanis were detained by law enforcement while fleeing the attack and were later released although others remained in detention, Ali said, adding he was not aware of any arrests or whether a motive for the attack had been identified.
Pakistan has offered Oman its full assistance in the investigation, Prime Minister Shehbaz Sharif wrote on X.
The US embassy in Muscat said it was following the situation closely.
"US citizens should remain vigilant, monitor local news and heed directions of local authorities," it said in a statement.
Oman has maintained its neutrality in the turbulent region and mediated in disputes, including between the United States and Iran.