Sahih Muslim 3770
The Book of Emancipating Slaves
حَدَّثَنَا يَحْيَى بْنُ يَحْيَى، قَالَ قُلْتُ لِمَالِكٍ حَدَّثَكَ نَافِعٌ، عَنِ ابْنِ عُمَرَ، قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم " مَنْ أَعْتَقَ شِرْكًا لَهُ فِي عَبْدٍ فَكَانَ لَهُ مَالٌ يَبْلُغُ ثَمَنَ الْعَبْدِ قُوِّمَ عَلَيْهِ قِيمَةَ الْعَدْلِ فَأُعْطِيَ شُرَكَاؤُهُ حِصَصَهُمْ وَعَتَقَ عَلَيْهِ الْعَبْدُ وَإِلاَّ فَقَدْ عَتَقَ مِنْهُ مَا عَتَقَ" .
Ibn Umar (Allah be pleased with them) reported Allah's Messenger may peace be upon him) as saying:If anyone emancipates his share ina slave and has enough money to pay the full price for him, a fair price for the slave should be fixed, his partners given their shares, and the slave be thus emancipated, otherwise he is emancipated only to the extent of the first man's share
Text from the public-domain hadith-api dataset. Numbering follows that dataset and can differ by a few from some printed editions — check the wording, not only the number.