Sayyiduna Abdullah bin Abbas (may Allah be pleased with them both) said: The Messenger of Allah (peace and blessings be upon him) was in Makkah; he (peace and blessings be upon him) was commanded to emigrate, and this verse was revealed to him (peace and blessings be upon him): "And pray thus: O my Lord! Wherever You take me, take me in well, and wherever You bring me out, bring me out well, and appoint for me from Yourself an authority and a helper" [Surah al-Isra': 80].
Hadith Referenceالسنن الكبرى للبيهقي / كتاب السير / 17736