The Prophet Muhammad (pbuh) was invited to Madinah to unite two tribes. He came with about 300 Muslims. During the next 10 years, until his (pbuh) death, most of the arabian peninsula had accepted him as the Prophet of God.
The second battle of Islam took place at Uhud , when the Makkans came to attack them. The Prophet (pbuh) himself got injuried during this battle, and many Sahaba (r.a) were martyred.
While in Madinah, the Quran revelaed to the change of direction from Jerusalem to Makkah. Someone were praying here, when others told them to turn around. This is the Mosque of the two Qiblas (directions).