Muhammad left Mecca, in 622 CE, after he was warned about a plot to assassinate him. The migration of the Prophet and his followers from Mecca to Medina is known as Hijra or Hegira.
After leaving his home in Mecca, Muhammad hid for three days in the Cave of Thawr, located south of his home city. He then traveled north and arrived at Quba' near Medina on July 2, 622. He moved from Quba' to Medina, two weeks later.
According to the Islamic faith, the Prophet was commanded by Allah to leave Mecca for Medina. The plot to assassinate him was the result of his preaching of the revelations God bestowed upon him. He could not preach in public and he had several opponents and enemies in Mecca. Medina was the place where Muhammad started to attract more and more followers.
For the next ten years, the city remained Muhammad's base, from where they marched to Mecca and conquered it without battle. Today, Medina is considered the second holiest place in Islam and is often referred to as the "City of the Prophet," home of the "Prophet's Mosque". After the death of the Prophet Muhammad, Medina remained an important center and was considered the de facto capital of the Caliphate.