The events of this story take place in 17th century Istanbul. The story is about a young Italian scholar sailing from Venice to Naples who is taken prisoner by the Ottoman Empire. Soon after, he becomes the slave of a scholar known as Hoja (master), a man who is about his own age, and with whom he shares a strong physical resemblance.
Hoja reports to the Pasha, who asks him many questions about science and the world. Gradually Hoja and the narrator are introduced to the Sultan, for whom they eventually design an enormous iron weapon.
The slave is told to instruct the master in Western science and technology, from medicine to astronomy. But Hoja wonders why he and his slave are the persons they are and whether given knowledge of each other's most intimate secrets, they could actually exchange identities.