During the pilgrimage seasons, the Prophet ﷺ met people from Yathrib, the town later called Madinah. In two pledges at al-ʿAqabah near Mina, its Muslims promised to believe, to obey, and to protect him as they protected their own families. He sent Musʿab ibn ʿUmayr to teach them, and Islam spread quickly there. The Muslims of Makkah began to migrate in small groups.
Quraysh plotted to kill him, with young men from every clan striking together so that no single clan could be blamed (8:30). That night ʿAli slept in his bed, and the Prophet ﷺ left with Abu Bakr. They hid for three nights in the Cave of Thawr, south of Makkah. When the searchers stood at its mouth, Abu Bakr was afraid, and the Prophet ﷺ reassured him: "Do not grieve; indeed Allah is with us" (9:40).
They then took an unusual route along the coast with a hired guide. Suraqah ibn Malik chased them for the reward Quraysh had offered, but his horse sank into the sand again and again; he asked for safety and turned back, later embracing Islam.
After about two weeks they reached Quba on the outskirts of Madinah, where the Prophet ﷺ founded the first mosque. He then entered Madinah to an overjoyed welcome. This journey, the Hijrah, later marked the start of the Islamic calendar.