The book follows the early adventures of Bartimaeus in service to King Solomon.
The story opens in Jerusalem with the djinni Bartimaeus currently in the service of one of the seventeen High Magicians of King Solomon of Israel, whom the king rules with the use of a mighty Ring. Ezekiel commands Bartimaeus to retrieve a magical artifact from the ancient city of Eridu. Bartimaeus succeeds, and then tricks the magician into commanding him to use the artifact against him. It sends a spurt of water at him, knocking him from his protective circle. Bartimaeus devours the old man and by the magician's death is released and returns to the Other Place.
The king, upon learning of Bartimaeus's murder of Ezekiel, is insulted that a mere djinni is the perpetrator. To make Bartimaeus pay for his actions he commands Khaba, an Egyptian and another of the seventeen, to summon Bartimaeus back into his service and punish him. The king also proposes to the queen of Sheba and is refused.
The scene shifts to the Sheban capital of Marib where Balkis, the aforementioned queen, receives a message from a fierce marid supposedly in Solomon's service: either pay a ransom of 40 sacks of frankincense or be destroyed, and gives her two weeks to pay. Balkis decides to send her loyal guard captain Asmira to Jerusalem to assassinate Solomon.
Back in Jerusalem, now in Khaba's service, Bartimaeus is commanded to perform many degrading jobs, including grain counting, sewage treatment, and artichoke collecting. Another unpleasant element is that one of his fellow slaves is his old rival Faquarl. Khaba assembles the eight djinn under his command and informs them that they have been commissioned to build Solomon's Temple on the Temple Mount and that they are to build it without using any magic whatsoever. Bartimaeus uses his trademark wit to infuriate Khaba and the magician unleashes his flail upon the djinn and threatens to place them in his essence cages (devices similar to the Mournful Orb in The Amulet of Samarkand) should they displease him a second time.
At first, Khaba and his subordinate closely supervise the stages of construction but after a while they stop showing up at the building site and the attitudes of the djinn grow lax. They begin assuming nonhuman forms and start using magic to build the temple (both actions directly in violation of Solomon's edicts). Several days later, Solomon makes an unexpected appearance on the building site. The other djinn manage to revert to human form and disguise their use of magic but Bartimaeus is caught in the form of a pygmy hippopotamus in a skirt (a comic reference to one of Solomon's 700 wives, "the one from Moab"). The king interrogates Bartimaeus and the djinni reluctantly admits his guilt while covering for the other spirits. As Solomon prepares to use the Ring on Bartimaeus, the djinni resorts to groveling in order to appease the king. Bartimaeus's pathetic display amuses Solomon, who agrees to spare the djinni's life and instead punishes him (and Khaba, whom Solomon blames for failing to keep his spirits in line) by sending them to hunt down the local bandits.
Several days later, out in the desert, Bartimaeus and Faquarl find and defeat bandits attacking the traveler Asmira. Faquarl insists on eating her but Bartimaeus hopes she can intercede with Khaba on their behalf. Asmira is then escorted to Jerusalem by Khaba and manages to persuade him to reluctantly dismiss the two djinn. Faquarl gains his freedom but Bartimaeus is imprisoned in a small bottle by Khaba and his principal slave, the marid Ammet, as punishment for his earlier crimes. Asmira tries to use her feminine wiles to convince Khaba to get her near Solomon but fails. Asmira frees Bartimaeus from the bottle and commands him as his new master to help her kill Solomon. The pair sneak through the palace gardens and scale the tower wall to Solomon's chamber, evading obstacles through Bartimaeus' magical efforts.
They encounter the king in his observatory and Asmira stabs him with her dagger, only to discover that it is an illusion set up to trap them. Bartimaeus escapes, but Asmira is captured and taken before the true King Solomon. Meanwhile Bartimaeus encounters the trapped afrit Philocretes and learns the secret behind Solomon and the Ring, that it causes immense pain to the bearer, in this case King Solomon. He then sneaks into the chamber where Solomon is interrogating Asmira and steals the Ring. Asmira takes the Ring from him, only to discover that its energies indeed inflict pain upon whoever touches it or uses it. Solomon then maintains that he never sent any ransom demand to Sheba, which causes Asmira to doubt herself and her loyalty to Queen Balkis. In the end, Asmira refrains from killing the king, choosing instead to take the Ring back to Sheba in spite of Solomon's warnings and Bartimaeus' demoralizing analysis of her motives. Suddenly Khaba arrives, subdues both girl and djinni and claims the Ring for himself. Khaba commands the Spirit of the Ring to destroy several of his rival magicians as well as Solomon's palace, but Asmira manages to use her last throwing knife to slice off Khaba's finger, with the ring still on it, and commands Bartimaeus to throw it into the sea. Although weakened by his use of the Ring, Khaba attempts to destroy both Asmira and Solomon, who manage to hold off Khaba's other servants for a brief time.
Meanwhile Bartimeaus has fled the palace with the powerful Ammet in hot pursuit. The two eventually reach the shores of the Mediterranean Sea and, Bartimaeus dips the ring in the sea, fulfilling his command. In an unexpected move, he then puts the Ring on and commands the Spirit to seal Ammet inside a wine jar at the bottom of the sea for a few thousand years. Returning to Jerusalem, Bartimaeus knocks out Khaba and returns the Ring to Asmira who gives it back to Solomon. The king imprisons Khaba and pardons both Asmira and Bartimaeus for their deeds. Solomon then summons Queen Balkis to Jerusalem and clears up the misunderstanding. However, a spiteful Balkis disowns her loyal guard from her service. Solomon then offers Asmira the opportunity to work for him instead.
In the aftermath of the attack, Asmira willingly dismisses Bartimaeus, revealing her intention to turn down Solomon's offer in favour of choosing her own path in life, and the two part ways on friendly terms.