The Man Who Would Be King is structured as a story within a story. The narrator, a British adventurer in India who may or may not be a newspaper correspondent of sorts, but who later becomes a real newspaperman and earns a measure of respectability, relates a story about two men he met in India who set out to become kings in the fictional nation of Kafiristan. One returns to tell the tale. Afterwards, the narrator attempts to help him but is unsuccessful.
The narrator describes a scene on a railway train that runs from Ajmir to Mhow. He is traveling not in first or second class but in Intermediate class, which he describes as very unpleasant due to the smells, the lack of cushions, and the occasional presence of a dead body. He meets a huge gentleman with a taste of whiskey and remarkable eyebrows that are not split apart, but that continue in an unbroken line across his forehead. This man relates his various adventures and wants to send a telegram back to Ajmir to contact a friend. The narrator is persuaded to stop at Marwar junction, to find a specific man and deliver a message. The stranger appeals to the narrator as a fellow Freemason, and makes use of specific phrases that indicate his status as an initiate. Accordingly, eight days later after a sojourn among many different classes of Indian society, the narrator locates the large, red-bearded man in the second-class car on the train and delivers the message. Because the two men the narrator meets appear to be trying to blackmail an official in Degumber, and because blackmail is not the kind of activity the narrator wants to have associated with the British newspapers, he reports them to the local authorities and succeeds in having them turned back at the Degumber border.
Several months later, after the narrator has become a respectable newspaperman, the two adventurers return and accost him one June night after he finishes up at the printing press. They invite themselves into his office, insist on a drink of whiskey, and finally introduce themselves. The large-shouldered man with the impressive eyebrows in Peachey Carnehan, and the large red-bearded man is Daniel Dravot. They want the narrator to be a witness to a contract they are making with one another. They propose to travel to the nation of Kafiristan (a fictional place somewhere in northern Afghanistan) and establish themselves as kings. To that end, they have drawn up a very simple contract in which they promise to stay away from liquor and women until they have established themselves as kings, and promise each other aid in the case of trouble.
Dravot and Carnehan have spent at least six months thinking their plan through. They are using the newspaperman for information: they want to know everything about Kafiristan. Both the men can read, however they aren't particularly educated. Dravot figures out a possible route, and the men pore over the newspaper office's collection of books that contain information about the region and the tribes that occupy it. The narrator leaves the two of them studying their books and making notes on the back of their contract. At the time, the narrator thinks the two adventurers are slightly unbalanced but probably harmless.
The next morning, the narrator encounters the two adventurers again. Dravot is disguised as a mad priest, and Carnehan is his assistant. The disguise is so good that the narrator does not recognize either of them. He follows Dravot out of the city where the two adventurers show him their twenty contraband Martini rifles. The narrator gives him a compass charm from his watch-chain and watches the two depart. Ten days later, he gets a letter from a friend in Peshawar who describes a mad priest who has joined a caravan headed to Kabul. The narrator wishes the best of luck for them, but is almost immediately distracted by the immediate need to write an obituary.
Three years later, a crippled man appears in the narrator's office. He is bent nearly into a circle, with his head sunk between his shoulders. He moves his feet cautiously, like a bear, and is wrapped in rags. Asserting that he had come back, he demands a drink. His face is drawn, his hair is gray, and the only thing about him that the narrator recognizes is eyebrows that meet over his nose in a black band an inch thick. But it isn't until he reintroduces himself that the narrator recognizes Peachey Carnehan.
Peachey discourages the narrator from looking at his wounded hands and feet, and begs the narrator to listen to him. He then picks up the story and allows the narrator to basically interview him.
Peachey describes how he and Dan went almost all the way to Jagdallak with the caravan, but turned off the road. This was a poor decision, because the camels could not continue. They changed disguises, at Dan's behest, and attempted to buy mules from some local men. The local men tried to rob them, but Dan killed one of them and the other ran away, so they took the mules for nothing.
Presently the two Englishmen encountered a group of ten men fleeing from a group of twenty. Since the local men are armed with only bows and arrows, Dan and Peachey decide to fight on the side of the group of ten. They use the rifles to pick off the twenty men from outside bow range, and intimidate the ten men into carrying the rifle boxes and supplies. Although neither of the Englishmen can communicate verbally with the locals, they manage to make their intentions clear with gestures. They pick twenty men in the first two villages they conquer, and teach them the basics of rifle drill. From there they pick a chief as an ally and begin their conquest. Some of the villages they overrun have primitive matchlocks, which are nowhere near as powerful or accurate as the Martini rifles.
Dan leaves Peachey to manage the vililages that have been conquered so far, and takes his army farther into Kafiristan. He returns after about three months to inform Peachey that the two of them are regarded as gods. They have had a lucky break: some earlier travelers to the region introduced Freemasonry, and a form of it has remained as a cult religion among the local priests. The two Englishmen are Third Degree Masons, Grand-Masters of the Craft, but the locals only know up to the second degree. Accordingly, the Englishmen are regarded as gods who possess hidden knowledge and wisdom. To consolidate their hold over the area, Dan proposes to set up a Lodge to initiate some of the other local chiefs. Peachey does not like the idea of exceeding their authority that way, but eventually participates and teaches the local women to make Masonic aprons. They bluff their way through the first two degree rituals and make up a Third Degree ritual that was not in any way according to the normal standard.
Over the next six months, Dan learns the local language and earns the love of the people. Peachey, who is unable to learn the language, plows and sets up rope bridges. He also travels to Ghorband to buy more guns and ammunition. Meanwhile, Dan's ambitions are growing. Instead of a nation, Dan wants to build an empire. He regards his subjects as English, and describes how he wants to send for administrators from India and some Snider rifles. There are about two million people in Kafiristan, and Dan believes he can build them into an effective fighting force to keep Russian interests out of India. Peachey resents that Dan wants the help of Britons besides himself. Meanwhile, winter is coming and the trade routes are starting to shut down.
As part of his plan to consolidate his empire, Dan proposes to take a wife. Peachey is against it because it violates their contract. Intuitively, Peachey senses that the kings are not as secure as they appear to be. They put the matter before the Council, which remained silent. Billy Fish, one of their first allies and a powerful chief of Bashkai, explains that it's best to ask the girls. He also explains that gods and mortals should not intermarry, because the woman who marries a god will invariably die or never be seen again. Nonetheless, a girl is selected for Dan to marry the following morning.
The morning of the wedding, Billy and Peachey try again to persuade Dan to give the marriage idea up. He will not. So Billy promises to see them safely to Bashkai until the backlash is over. Dan, who insists there will be no row, insists that the girl be brought out. The young woman appears, well dressed but terrified. When Dan puts his arm around her, she bites him on the face. The sight of Dan's blood makes the local people realize that Dan and Peachey are not in fact gods, but mortal men. They riot. With help from Billy Fish and his flintlock-wielding retainers, Dan and Peachey get away from the immediate area.
Peachey and Billy try to persuade Dan to run, but he is too busy blaming Peachey for not predicting the rebellion to move quickly. They walk as quickly as they can, but are poorly provisioned and eventually find themselves cut off by Kafir people carrying rifles the Englishmen had brought with them. Dan and Peachey fire their last cartridges, but are overcome. The local people cut Billy Fish's throat on the spot and march Dan a mile to the center of one of the rope bridges which span chasm over a river. They cut either the rope or Dan's head; the text is ambiguous. In any case, Dan's body falls onto a rock in the river below. They crucify Peachey, but when Peachey lives through the night they help him recover in the temple. Then they give him Dan's head, crown and all, as a reminder to never return. Peachey then makes his slow, painful way back to India.
The narrator relates how Peachey takes Dan's head out of a bag and shows it to him, along with the crown. Peachey refuses all offers of help, and shambles off saying he is headed toward Marwar. But later that day the narrator spies a crooked man on the side of the road, singing about the Son of Man and his golden crown. He brings the man, who might well be Peachey, to the missionary hospital for eventual transfer to the Asylum. Unfortunately, the man the narrator brings in dies shortly afterwards and the crowned head of Daniel Dravot is never found.
The reader is given to understand that the man who died is in fact Peachey, and the last paragraph explains the narrator's first-paragraph musings about how "his" king is dead.