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.
Gradually Hoja and the narrator are introduced to the Sultan, for whom they eventually design an enormous iron weapon.
The story begins with a frame tale in the form of a preface written by historian Faruk Darvinoglu (a character referenced in Pamuk's previous book, Silent House) between 1984 and 1985, according to the fictional dedication to the character's late sister at the beginning of the frame tale.
Faruk recalls finding the story that follows in a storage room while looking through an archive in the governor's office in Gebze, among old bureaucratic papers.
During his breaks from work, he begins trying to find a source for the tale, hoping to authenticate its events and author.
The preface ends with Faruk noting that the publisher chose the title of the book, and a remark on the nature of modern readers will try to connect the dedication to his sister to the tale that follows.
The story proper begins with an unnamed narrator being captured by the Turkish fleet while sailing from Venice to Naples.
He is surprised when Hoja tries to tout a poorly translated copy of Almageist, which receives a lukewarm reaction from the narrator.
Hoja reveals his goal of gaining the sultan's favor in order to obtain the position as court astrologer.
Competing over the influence of the sultan's mother and his youthful impatience, he sets out to create a great weapon that will prove his brilliance, and that of the Ottoman Empire's.
The narrator learns from a distance that the weapon has not only failed, but that the Poles that they were attacking have obtained reinforcements from Hungary, Austria and the Cossacks.
He is married, with children, and has done quite well financially while he worked as royal astrologer, though he resigned his post before the intrigue got him killed.
A traveling author, Evliya Chelebi, seeks him out, hoping to learn about Italy, as he'd once owned an Italian slave.
Hoja, the master, tries to assume superiority over the narrator several times throughout the story, whether by ridiculing him for his childhood, or for his weakness and paranoia as a slave.