Sunan an-Nasa'i, Book 39, Hadith 18 (In-Book)

It was narrated that Jabir bin Zaid said: "Ibn 'Abbas said: 'The Messenger of Allah, Abu Bakr and 'Umar were among the Muhajirin (emigrants), because they forsook (hajaru) the idolators, and some of the Ansar were Muhajirun because Al-Madinah was a land of shirk, and they came to the Messenger of Allah on the Night of Al-'Aqabah."'

أَخْبَرَنَا الْحُسَيْنُ بْنُ مَنْصُورٍ، قَالَ حَدَّثَنَا مُبَشِّرُ بْنُ عَبْدِ اللَّهِ، قَالَ حَدَّثَنَا سُفْيَانُ بْنُ حُسَيْنٍ، عَنْ يَعْلَى بْنِ مُسْلِمٍ، عَنْ جَابِرِ بْنِ زَيْدٍ، قَالَ قَالَ ابْنُ عَبَّاسٍ إِنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم وَأَبَا بَكْرٍ وَعُمَرَ كَانُوا مِنَ الْمُهَاجِرِينَ لأَنَّهُمْ هَجَرُوا الْمُشْرِكِينَ وَكَانَ مِنَ الأَنْصَارِ مُهَاجِرُونَ لأَنَّ الْمَدِينَةَ كَانَتْ دَارَ شِرْكٍ فَجَاءُوا إِلَى رَسُولِ اللَّهِ صلى الله عليه وسلم لَيْلَةَ الْعَقَبَةِ ‏.‏

sunnah.com