Alexander the Great had transferred Greek culture to the reaches of Asia. In the valley of Fergana, in present-day Tajikistan, he had founded Alexandria Echati, on the Yaxarti river (present-day Sir Darya), which he colonized with Greeks.
The local Greeks and locals lived under the Hellenistic kingdom of Bactria until 160 BC. ca., when barbarian tribes conquered the surrounding area and isolated them. The Greeks in the 3rd c. e.g. they had campaigned as far as Chinese Turkmenistan and the Yunnan region. The kingdom of the Greeks and their descendants in Fergana was known to the Chinese as Dayuan which loosely translates to "great Ionians", i.e. Greeks.
The Greeks of Alexandria Echati (today's Khuzad) maintained relations with China during the Han Empire period. According to a Chinese traveler who had moved to the kingdom around 130 BC. the Dayuan country had Alexandria the Great as its capital, a high culture and an army of 60,000 men.
The war
The conflict between Han China (202 BC – 9 AD &25 AD – 220 AD) and the Hellenistic kingdom, according to Chinese tradition, was caused by the refusal of the Greeks to sell to the Chinese war horses that they had for the needs of the Chinese emperor's army.
This was considered a great insult, and Emperor Wu ordered his general Li Guang Li to campaign against the arrogant Dayuan, providing him with 6,000 cavalry and 20,000 infantry recruited from the dregs of Chinese society.
In 104 BC the Chinese army started. The Chinese were obliged to cross Xinjiang and the Taklamakan desert, counting on getting the necessary supplies from the local governors in the oases there. However, the latter proved unwilling and the Chinese had to fight, burn and loot several times.
Continuing their arduous march the Chinese reached the borders of Dayuan but by then their army had suffered terrible attrition. As if this was not enough, the Chinese were soundly defeated in the battle of Yucheng and badly - badly retreated. The Chinese army was completely destroyed.
Nevertheless, the emperor was not disappointed. In 102 BC he assembled a huge army of 60,000 infantry and 30,000 cavalry followed by 100,000 cattle and 20,000 yoke of oxen. The Chinese, under General Li again, followed the same course, but this time the strength of their forces left no room for the sentinels. Thus they passed through Xinjiang and the desert without serious problems.
The huge Chinese army arrived at Alexandria Echati which the Chinese called Ersi and besieged it. The defenders attempted an exit but were repulsed. The siege was not going well for the Chinese, until they managed to cut off the city's water supply.
However, it was only after 40 days of fierce wall fighting that the Chinese managed to breach the outer wall and enter part of the city . Retreating to the inner wall, a portion of the nobles demanded a conditional capitulation.
The Chinese, exhausted themselves, accepted but asked for the head of the king of the city, who in Chinese texts is referred to as Wugua, which the traitorous nobles handed over to him. He also demanded the delivery of 3,000 warhorses.
Departing, without having captured the city, the Chinese general Li Guang Li enthroned one of their royal nobles, called in Chinese texts Mikai, and departed.
Of their 90,000 men, however, only 11,000 returned due to wear and tear during the siege mainly, since in their second campaign the Chinese had food with them, food was also given to them by the Dayuans, after the treaty and they were not harassed by local wardens except in rare cases.
Yet the Chinese campaign essentially failed. In 101 BC the Dayuan nobles killed King Mikai who was considered a puppet of the Chinese and put the dead King Wugua's brother on the throne. The Chinese did not retaliate and were limited to reestablishing trade and diplomatic relations with the Dayuan kingdom. The war of the "heavenly horses" ended with a strategic defeat of the Chinese.