In 804 Kuukai took part in a government-sponsored expedition to China in order to learn more about the Mahavairocana Sutra. Scholars are unsure why Kuukai was selected to take part in an official mission to China, given his background as a private, not state-sponsored, monk. Theories include family connections within the Saeki-Ootomo clan, or connections through fellow clergy or a member of the Fujiwara clan.
The expedition included four ships, with Kuukai on the first ship, while another famous monk, Saichou was on the second ship. During a storm, the third ship turned back, while the fourth ship was lost at sea. Kuukai's ship arrived weeks later in the province of Fujian and its passengers were initially denied entry to the port while the ship was impounded. Kuukai, being fluent in Chinese, wrote a letter to the governor of the province explaining their situation. The governor allowed the ship to dock, and the party was asked to proceed to the capital of Chang'an (present day Xi'an), the seat of power of the Tang Dynasty.
After further delays, the Tang court granted Kuukai a place in the Ximingsi temple where his study of Chinese Buddhism began in earnest as well as studies of Sanskrit with the Gandharan pandit Prajna who had been educated at the Indian Buddhist university at Nalanda.
It was in 805 that Kuukai finally met Master Huiguo, the man who would initiate him into the esoteric Buddhism tradition at Changan's Qinglong Monastery (青龍寺). Huiguo came from an illustrious lineage of Buddhist masters, famed especially for translating Sanskrit texts into Chinese, including the Mahavairocana Sutra.
Huiguo immediately bestowed upon Kuukai the first level Abhisheka or esoteric initiation. Whereas Kuukai had expected to spend 20 years studying in China, in a few short months he was to receive the final initiation, and become a master of the esoteric lineage. Huiguo was said to have described teaching Kuukai as like "pouring water from one vase into another". Huiguo died shortly afterwards, but not before instructing Kuukai to return to Japan and spread the esoteric teachings there, assuring him that other disciples would carry on his work in China.
Kuukai arrived back in Japan in 806 as the eighth Patriarch of Esoteric Buddhism, having learnt Sanskrit and its Siddham script, studied Indian Buddhism, as well as having studied the arts of Chinese calligraphy and poetry, all with recognized masters. He also arrived with a large number of texts, many of which were new to Japan and were esoteric in character, as well as several texts on the Sanskrit language and the Siddham script.
However in Kuukai's absence Emperor Kammu had died and was replaced by Emperor Heizei who exhibited no great enthusiasm for Buddhism. Kukai's return from China was eclipsed by Saichou, the founder of the Tendai school, who found favor with the court during this time. Saichou had already had esoteric rites officially recognised by the court as an integral part of Tendai, and had already performed the abhisheka, or initiatory ritual, for the court by the time Kuukai returned to Japan. Later, with Emperor Kammu's death, Saichou's fortunes began to wane.
Saichou requested, in 812, that Kuukai give him the introductory initiation, which Kuukai agreed to do. He also granted a second-level initiation upon Saichou, but refused to bestow the final initiation (which would have qualified Saichou as a master of esoteric Buddhism) because Saichou had not completed the required studies, leading to a falling out between the two that was not resolved.
Little is known about Kuukai's movements until 809 when the court finally responded to Kuukai's report on his studies, which also contained an inventory of the texts and other objects he had brought with him, and a petition for state support to establish the new esoteric Buddhism in Japan. That document, the Catalogue of Imported Items, is the first attempt by Kuukai to distinguish the new form of Buddhism from that already practiced in Japan. The court's response was an order to reside in the Takaosan (later Jingo-ji) Temple in the suburbs of Kyoto. This was to be Kuukai's headquarters for the next 14 years. The year 809 also saw the retirement of Heizei due to illness and the succession of the Emperor Saga, who supported Kuukai and exchanged poems and other gifts.