Mishkat al-Masabih 3969
‘Imran b. Husain said:
Thaqif were allies of the B. ‘Uqail, so when Thaqif took two of God’s Messenger’s companions prisoner, his companions took prisoner a man of the B. ‘Uqail, bound him and threw him out on the lava plain. God’s Messenger passed him and he called to him, “Muhammad, Muhammad, for what have I been taken?” He replied, “For the crime of your allies Thaqif.” He then left him and passed on, but when he cried, “Muhammad, Muhammad,” God’s Messenger took pity on him and returned and asked him about himself. When he told him he was a Muslim he said, “If you had said it when you were your own master you would have been completely successful.”* Then God’s Messenger ransomed him for the two men Thaqif had taken prisoner. 

*This means that not only would he go to paradise in the next life, but he would have been saved the experience of being taken a captive in this.

Muslim transmitted it.
وَعَن عمرَان بن حُصَيْن قَالَ: كَانَت ثَقِيفٌ حَلِيفًا لِبَنِي عُقَيْلٍ فَأَسَرَتْ ثَقِيفٌ رَجُلَيْنِ مِنْ أَصْحَابِ رَسُولِ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ وَأَسَرَ أَصْحَابِ رَسُولِ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ رَجُلًا مِنْ بَنِي عُقَيْلٍ فَأَوْثَقُوهُ فَطَرَحُوهُ فِي الْحَرَّةِ فَمَرَّ بِهِ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ فَنَادَاهُ: يَا مُحَمَّدُ يَا مُحَمَّدُ فِيمَ أُخِذْتُ؟ قَالَ: «بِجَرِيرَةِ حُلَفَائِكُمْ ثَقِيفٍ» فَتَرَكَهُ وَمَضَى فَنَادَاهُ: يَا مُحَمَّدُ يَا مُحَمَّدُ فَرَحِمَهُ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسلم فرجعَ فَقَالَ: «مَا شَأْنُكَ؟» قَالَ: إِنِّي مُسْلِمٌ. فَقَالَ: «لَوْ قُلْتَهَا وَأَنْتَ تَمْلِكُ أَمْرَكَ أَفْلَحْتَ كُلَّ الْفَلَاحِ» . قَالَ: فَفَدَاهُ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ بالرجلينِ اللَّذينِ أسرَتْهُما ثقيفٌ. رَوَاهُ مُسلم