There is an ancient mosque built in the early 7th century at Kodungallur (629 CE) on the southwest coast of Kerala, India, known as Cheraman Malik Masjid which still exists in its original structure and is said to be the first mosque in the Indian sub-continent.
In fact it could be the second oldest mosque in the world, second only to the Holy Prophet’s mosque in Medina. The story of this mosque is connected to the Hindu King Cheraman Perumal Rama Varma Kulashekhara the Chera ruler of the principality of Kodangallur in Kerala and to the miraculous splitting of the moon by the Holy Prophet Muhammed in Mecca, Arabia (peace and blessings be upon him).
The splitting of the moon is mentioned in the Holy Qur'an, Surah Al-Qamar (54:1-3). This supported by several hadith of which one is narrated by Anas bin Malik: "The people of Mecca asked Allah's Messenger to show them a miracle. So he showed them the moon split in two halves between which they saw the Hiram' mountain. (Translation of Sahih Bukhari, Merits of the Helpers in Madinah (Ansaar), Volume 5, Book 58, Number 208)".
India’s first contact with Islam was in Kerala, where for centuries before the rise of Islam Arab traders would visit local ports to trade. For Arabs, Malabar was the most familiar place in the whole Indian subcontinent. The relationship between Arabs and Malabar is a history that goes back centuries. Arab merchants were trading spices such as ginger, pepper and cardamom in return for finely crafted swords, ivory and silk from Malabar. These were precious as well as prestigious commodities in Arab souks. A Malabari sword, an icon of the best blacksmith craftsmanship was a status symbol for Arabs. Cultural exchange also took place through Arab merchants. Hence, names of places in Malabar and their customs were quite familiar among the traders of Okaz souk in Taif. Arabs often selected Hind as name for their daughters. Similarly, residents of Malabar were well aware of the changes happening in the Arabian Peninsula.
When the moon was split into two, a divine miracle done by Prophet Muhammad, many people inside and outside the Arabia witnessed it. The king Cheraman Perumal while walking on the rooftop of his palace with his queen saw the full moon suddenly splitting into two halves. He did not know then that he had just witnessed a wonderful miracle being performed thousands of miles away in Mecca by the Prophet to convince the unbelieving people of Mecca who had challenged his prophet-hood.
It did not take much time for the news to spread in Malabar, through Arab merchants, about the emergence of a prophet named Muhammad (s) in Mecca and his religion Islam. Sometime later a group of Arabs came to Kodungallur to meet the king and get permission to visit Ceylon (present Sri Lanka). They wanted to visit the mountain which holds the imprint of the footsteps of Adam, the first human being and the first prophet. King Cheraman asked his Arab guests about the miraculous moon-splitting incident in their land. The visiting Arab traders explained to the king that the miracle was a sign that a prophet had been sent by God to Arabia.
Impressed by this new messenger of God in Arabia the king wanted to meet the holy Prophet. The Arab visitors returned to Kodungallur from Ceylon, King Cheraman set off with them on their way back to Arabia. The king left after dividing his kingdom and assigning various territories to local chieftains to ensure smooth governance.
In Arabia he met the Prophet (s) and embraced Islam at his hands and in the presence of several companions. This historical meeting is mentioned in the Hadith by Imam Bukhari and Abu Saeed Al-Khudri. The Hadith says: “A king from India presented the Messenger of Allah with a bottle of pickle that had ginger in it. The Prophet distributed it among his companions. I also received a piece to eat.” This is incident is corroborated by the manuscript documented by the royal court scribes and this is archives in the India Office Library, London which has reference number Arabic. 2807, 152-173.
King Cheraman was given a Muslim name Tajuddin (meaning ‘crown of the religion’) by the Prophet (s). Thus King Cheraman became the first Indian to accept Islam. Under the Prophet’s instructions, along with a team of his companions led by Malik bin Dinar, King Tajuddin started the journey back to Kerala to propagate Islam there. But along the way the king fell sick. King Cheraman wrote letters to his vicegerents to receive Malik Bin Dinar’s team and to give them all necessary help. In the letters he asked them to "receive the bearers of the letters and treat them well and help them to construct mosques at Kodungallur and elsewhere" The king passed away and was buried on the shore of the Arabian Sea at Salalah in the Sultanate of Oman.
The rulers of Kerala honoured the letters and permitted Malik Bin Dinar and his fellow Arab traders to build mosques in Kerala. Some history books say that a temple named Arathali was converted to a mosque and named after Cheraman in Kodungallur. Malik Bin Dinar and his colleagues built mosques in 12 places. Surprisingly all of them are situated along the coastal areas of Arabian Sea. Malik Bin Dinar died when he was in Butkal, Karnataka and is buried there.
The Malabar Coast had conducted trade with the west since before the Greek and Roman periods and already played host to communities of Jews, Christians and Manicheans. The dates on Muslim graves of the first nine mosques in Kerala are from the late eighth century CE, which appears to synchronize with the historical king Cheraman Perumal, the first Muslim of India.