The Quraysh starts persecuting the Muslims, beating them, allowing them no food or drink, and exposing them to the burning heat of Mecca. Some gave way under the pressure of persecution, and others resisted.
So it became virtually impossible for Muhammad to continue preaching in Mecca. In September 622, after secret negotiations over the previous two years, he settled in the area of Medina, two hundred miles to the north, where seventy of his followers had already gone. This "emigration" (leaving one's living place for another) is the Hijra (Latin, hegira), on which the Islamic era is based.
Once Muhammad emigrated to Medina he made an agreement with the Jewish tribes of Yathrib (Medina). Any disputes were to be resolved by Muhammad (232). Once Muhammad was established in Medina he instituted prayers, fasting, alms tax, legal punishments and spelled out that which was forbidden and prescribed.
To teach Muhammad a lesson, the Meccans in March 625 invaded the Medinese area with about three thousand men. Many Muslims were killed before they could regain the safety of the hill. Militarily this was not a serious loss for Muhammad, since the Meccans had also suffered casualties and retreated immediately; but the loss shook the belief that God was defending him. Confidence was only gradually restored.
The next major event was the siege of Medina by ten thousand Meccans and allies in April 627. Muhammad protected the central part of the area by a trench that tricked the cavalry. After two weeks Meccans and their allies retreated. In March 628 the Meccans settled the Treaty of al-Hudaybiya with him. The treaty was a triumph for Muhammad. In the following months many nomadic (having to do with moving from area to area) tribesmen and a few leading Meccans joined Muhammad and became Muslims. When the treaty was criticized in January 630, Muhammad was able to march on Mecca with ten thousand men. Muhammad entered Mecca in triumph. Two weeks later two thousand joined Muhammad's army in opposing a concentration of tribesmen east of Mecca and shared in the victory of Hunayn.
For more details and benefits, please see these links:
Bography of porphet Muhammad
Muhammad Biography Blog