Jabir (may Allah be pleased with him) narrated that a slave pledged allegiance to the Messenger of Allah (ﷺ) for migration, and the Prophet (ﷺ) did not know that he was a slave until his owner came to take him back. So the Prophet (ﷺ) said: "Sell him." Thus, the Prophet (ﷺ) bought him in exchange for two Abyssinian slaves. After that, the Prophet (ﷺ) did not take allegiance from anyone until he asked whether he was a slave or free.
Hadith Referenceمسند الإمام الشافعي / كتاب البيوع / 1450
Hadith Takhrijاخرجه مسلم البيوع، باب جواز بيع الحيوان بالحيوان من جنسه متفاضلا (1602)۔