When the non believers made life difficult for the Prophet in Mecca, he returned the properties entrusted to him and left in the night with Abu Bakr to Medinah. They went south of Makkah to a mountain cave named 'Soor' and after staying there for three nights, traveled north to Medinah about two hundred and fifty miles from Makkah. Inspite of all the search made by the nonbelievers, Allah protected the Prophet and they arrived safely in Quba, a suburb of Medinah. They stayed at Quba and the first Mosque there was constructed which is known as Masjide Quba. This emigration is known as the ‘Hijrat’ (migration) and Islamic calendar begins with this event.
After his emigration to Medinah, the enemies of Islam did not keep quiet but fought three wars with the Muslims. Those wars in which the Prophet participated are known as Gazwa (e.g. the Gazwa of Badr, Ohad, Tabuk, Ahzab, Hunain, Khandaq (Trench), Mostalaq etc.) They were fought near or around Medinah and were well defended.
Best example of offering salats was taught on the battlefield. He taught his followers to pray in congregation to the Almighty. Even during the peak of a war, whenever it was time to pray, it was performed and never postponed. A batallion kept the enemy engaged while another was bowing their heads before Allah. After finishing the prayers, the two parties exchanged their positions.