The whole thing began when Muhammad (PBUH) started to preach to the people of Mecca, a major city in the Arab peninsula, to deliver the message of Allah that there was no God but Allah the creator of the universe and all people should worship only Allah according to the instructions of Islam as the previous religions had been altered.
At this time, the people of the Arab peninsula were worshipping idols in the form of statues. After Muhammad had preached publicly for more than a decade, the opposition to him reached such a high pitch that, fearful for their safety, he sent some of his adherents to Ethiopia, where the Christian ruler extended protection to them.
But in Mecca the persecution worsened. Muhammad's followers were harassed, abused, and even tortured. At last, therefore, Muhammad sent seventy of his followers off to the northern town of Yathrib, which was later to be, renamed Medina ("The City").
Later, in the early fall of 622, he learned of a plot to murder him and, with his closest friend, Abu Bakr al-Siddiq, set off to join the emigrants. Muhammad and Abu Bakr went on to Medina, where they were welcomed by a gathering of Medinans as well as the Meccans who had gone ahead earlier. This was the Hijrah from which the Muslim era is dated.
The modern map of the Arabian Peninsula showing the locations of old Mecca and Medina.
Muhammad was well acquainted with the situation in Medina. Earlier, before the Hijrah, the city had sent envoys to Mecca asking Muhammad to mediate a dispute between two powerful tribes. What the envoys saw and heard impressed them and they invited Muhammad to settle in Medina.
After the Hijrah, Muhammad's exceptional qualities so impressed the Medinans that the rival tribes and their allies temporarily closed ranks.
The emigration of Muhammad (PBUH) to Medina had turned the enemies of Mecca more hostile, and they constantly kept on thinking how they could overthrow him, and put an end to Islam.