Complex sentence: Yaqut was sold as a slave to someone who later moved to Baghdad, and who upon recognizing Yakut's abilities provided him with a good education.
Split into simpler sentences: Yaqut was sold as a slave to someone who later moved to Baghdad. Upon recognizing his abilities, Yaqut's purchaser provided him with a good education.