The novel, a black comedy, is set in Havana during the Fulgencio Batista regime. James Wormold, a vacuum cleaner retailer, is approached by Hawthorne, who offers him work for the British secret service. Wormold's wife had left him and now he lives with his sixteen-year-old beautiful, devoutly Catholic but materialistic and manipulative daughter Milly. Since Wormold does not make enough money to pay for Milly's extravagances, he accepts the offer of a side job in espionage. Because he has no information to send to London, Wormold fakes his reports using information found in newspapers and invents a fictitious network of agents. Some of the names in his network are those of real people (most of whom he has never met) and some are made up. Wormold only tells his friend and World War I veteran, Dr. Hasselbacher, about his spy work, hiding the truth from Milly.
At one point, he decides to make his reports "exciting" and sends to London sketches of what he describes as a secret military installation in the mountains, actually vacuum cleaner parts scaled to a large size. In London nobody except Hawthorne, who alone knows Wormold sells vacuum cleaners, doubts this report. But Hawthorne does not report his doubts for fear of losing his job. In the light of the new developments, London sends Wormold a secretary, Beatrice Severn, and a radio assistant codenamed "C" with much spy paraphernalia.
On arriving, Beatrice tells Wormold she has orders to take over his contacts. Her first request is to contact the pilot Raúl. Under pressure, Wormold develops an elaborate plan for his fictitious agent "Raúl" but, to his surprise, a real person with the same name is killed in an apparent car accident. From this point, Wormold's manufactured universe overlaps with reality, with threats made to his "contacts". Together, Beatrice (who doesn't realise the contacts are imaginary) and Wormold try to save the real people who share names with his fictional agents.
Meanwhile, London passes on the information that an unspecified enemy (implied to be a Soviet contact) intends to poison Wormold at a trade association luncheon where Wormold is the speaker. It would seem that his information has worried local operatives who now seek to remove him– London is pleased by this, as it validates his work. Wormold goes to the function and sees Dr. Hasselbacher who loudly warns him of the threat. Wormold continues to dinner where he manages to refuse the meal offered, and eats another one. Across the table sits a fellow vacuum cleaner salesman, aman he'd met earlier called Carter, who offers him whisky – suspicious, Wormold knocks over the glass, which is then drunk by the headwaiter's dachshund, which soon dies. In retaliation for the failure, Carter kills Dr. Hasselbacher at the club bar.
Captain Segura, a military strongman who is in love with Milly and intends to marry her, has a list of all of the spies in Havana– a list that Wormold would like to send to London to partially redeem his employment. He tells Segura that he's going to his house to discuss Segura's plans about Milly. Once there, Wormold proposes they play a game of draughts using miniature bottles of Scotch and Bourbon as the game pieces, where each piece taken has to be drunk at once. Eventually, Segura (who is the much better player) ends up drunk and falls asleep. Wormold takes his gun and photographs the list using a microdot camera. To avenge the murder of Dr. Hasselbacher, Wormold convinces Carter to accompany him on a drive and,at a local brothel and after some hesitation, shoots with Segura's pistol. He misses Carter and is about to leave, but Carter shoots back, and Wormold shoots and kills him. Wormold sends the agent list as a microdot photograph on a postage stamp to London but it proves blank when processed.
Wormold confesses everything to Beatrice, who reports him to London. Captain Segura has Wormold deported. Wormold and Beatrice are summoned to headquarters where Beatrice is posted to Jakarta and Wormold's situation is considered– to avoid embarrassment and silence him from speaking to the press, MI6 offers Wormold a teaching post at headquarters and recommends him for an OBE. Afterwards, Beatrice comes to Wormold's hotel and they decide to marry. Milly is surprisingly accepting of their decision, and is to go to a Swissfinishing school paid for by Wormold's scam earnings.