Islam during the Tang dynasty

The history of Islam in China goes back to the earliest years of Islam. According to the Chinese Old book of Tang Muslim missionaries reached China through an embassy sent by ʿUthmān ibn ʿAffān (644–656), the third rāshidūn caliph, in 651 CE, less than twenty years after the death of Muhammad (632 CE) in the second year of the third Tang Dynasty Emperor. Saʿd ibn Abī Waḳḳāṣ, the maternal uncle and second cousin of Muhammad, was sent with a delegation to meet the Emperor Gaozong of Tang. The construction of Huaisheng Mosque in Guangzhou, the first mosque in the country, is attributed to him.

Origins
According to the traditional accounts of Chinese Muslims, Islam was first brought to China by an embassy sent by Uthman, the third Caliph, in 651, less than twenty years after the death of Islamic prophet Muhammad. The embassy was led by Sa`d ibn Abī Waqqās, a companion of the Muhammad himself. According to tradition, Emperor Gaozong then ordered the construction of the Memorial mosque in Canton, the first mosque in the country, in memory of Muhammad. The traditional accounts state that the envoys visited more than 37 times between 651 and 798. In one of the delegations the envoy was asked to perform the kneeling greeting before the emperor in 712, but did not perform it, saying: "We only worship Allah, but there is no law of worship for the king. ''

While modern historians say that there is no evidence for Waqqās himself ever coming to China, they do believe that Muslim diplomats and merchants arrived to Tang China within a few decades from the beginning of the Muslim Era. The Tang dynasty's cosmopolitan culture, with its intensive contacts with Central Asia and its significant communities of (originally non-Muslim) Central and Western Asian merchants resident in Chinese cities, which helped the introduction of Islam.

Early contacts between Islam and China
Arab people are first noted in Chinese written records, under the name Dashi in the annals of the Tang dynasty (618–907), (Tashi or Dashi is the Chinese rendering of Tazi—the name the Persian people used for the Arabs). Records dating from 713 speak of the arrival of a Dashi ambassador. The first major Muslim settlements in China consisted of Arab and Persian merchants.

Arab sources state Qutayba ibn Muslim briefly took Kashgar from China and withdrew after an agreement but modern historians entirely dismiss this claim.

The Arab Umayyad Caliphate in 715 AD deposed Ikhshid, the king of the Fergana Valley, and installed a new king Alutar on the throne. The deposed king fled to Kucha (seat of Anxi Protectorate), and sought Chinese intervention. The Chinese sent 10,000 troops under Zhang Xiaosong to Ferghana. He defeated Alutar and the Arab occupation force at Namangan and reinstalled Ikhshid on the throne.

Chinese General Tang Jiahui led the Chinese to defeat the following Arab-Tibetan attack in the Battle of Aksu (717). The attack on Aksu was joined by Türgesh Khan Suluk. Both Uch Turfan and Aksu were attacked by the Türgesh, Arab, and Tibetan force on 15 August 717. Qarluqs serving under Chinese command, under Arsila Xian, a Western Turkic Qaghan serving under the Chinese Assistant Grand Protector General Tang Jiahui defeated the attack. Al-Yashkuri, the Arab commander and his army fled to Tashkent after they were defeated.

In 751 the Abbasid Caliphate defeated the Tang dynasty in the Battle of Talas River. The Tang dynasty saw the creation of the first Muslim embassy, with the exchange of an emissary from Emperor Gaozong of Tang, with a general from the Caliph Osman. There were also requests for help from the Muslim soldiers. In 756, a contingent probably consisting of Persians and Iraqis was sent to Gansu to help Emperor Xuanzong in his struggle against the An Lushan Rebellion. Less than 50 years later, an alliance was concluded between the Tang and the Abbasids against Tibetan attacks in Central Asia. A mission from the Caliph Harun al-Rashid (766–809) arrived at Chang'an. These diplomatic relations were contemporaneous with the maritime expansion of the Islamic world into the Indian Ocean and as far as East Asia after the founding of Baghdad in 762. After the capital was changed from Damascus to Baghdad, ships begin to sail from Siraf, the port of Basra, to India, the Malaccan Straits and South China. Canton, or Khanfu in Arabic, a port in South China, counted among its population of 200,000, merchants from Muslims regions.

In 851 Persian Muslim merchant Sulaiman al-Tajir mentions in his stay at the city of Guangzhou that the Muslim populace of the city was sizable enough that it had its own governing body to deal with intercommunal disputes.

Early Muslims in China
The earliest Chinese Islamic architecture was the Great Mosque in Xian was built in 742 (according to an engraving on a stone tablet inside), and the Daxuexi Alley Mosque in Xi'an (According to the inscription of the emperor Tian Qi (1620-1627) of the Ming Dynasty; the mosque was built in 705).

During the Tang dynasty a steady stream of Arab and Persian traders arrived in China through the silk road and the overseas route through the port of Quanzhou. The Muslim had their mosques in the foreign quarter on the south bank of the Canton River. Not all of the immigrants were Muslims, but many or some of them stayed. It is recorded that in 758, a large Muslim settlement in Guangzhou erupted in unrest and fled. The same year, Arab and Persian pirates who probably had their base in a port on the island of Hainan. This caused some of the trade to divert to Northern Vietnam and the Chaozhou area, near the Fujian border. The Muslim community in Canton had constructed a large mosque (Huaisheng Mosque), destroyed by fire in 1314, and reconstructed in 1349–51; only ruins of a tower remain from the first building.

Laws concerning religion
Islam was brought to China during the Tang dynasty by Arab traders, who were primarily concerned with trading and commerce, and not concerned at all with spreading Islam. They did not try to convert Chinese at all, and only did commerce. It was because of this low profile that the 845 anti Buddhist edict during the Great Anti-Buddhist Persecution said absolutely nothing about Islam. Early Muslim settlers, while observing the tenets and practicing the rites of their faith in China, did not undertake any strenuous campaign against either Buddhism, Confucianism, Taoism, or the State creed, and they constituted a floating rather than a fixed element of the population, coming and going between China and the West by the oversea or the overland routes.

The massacre of foreigners
Two massacres with Muslim victims took place in Tang dynasty China, the Yangzhou massacre (760), and the Guangzhou massacre.

In 878 recorded the massacre of Muslims in Guangzhou (Canton) by a rebel leader named Huang Chao. Abu-Zaid of Siraf reported that 120,000 foreign merchants were killed by Huang Chao, while the later Mas'udi claimed 200,000. The victims were Muslims, Jews, Christians, and Zoroastrians (Parsees). It was estimated that the number killed were between 120,000 and 200,000.

Arab geographer and traveler Abu Zaid Hassan recorded "no less than 120,000 Muslims, Jews, Christians, and Parsees perished". (Hourani 1995:76)