Delhi, India 1885. While working as a correspondent at the offices of the Northern Star newspaper, Kipling (Christopher Plummer) is approached by a ragged, seemingly crazed derelict, who reveals himself to be his old acquaintance Peachy Carnehan (Michael Caine). Peachy tells Kipling the story of how he and his comrade-in-arms Danny Dravot (Sean Connery) travelled to remote Kafiristan (a provence in modern-day Afghanistan), became gods, and ultimately lost everything.
Five years earlier. The pair of rogues had meet Kipling at his office. After signing a contract pledging mutual loyalty and forswearing drink and women until they achieved their grandiose aims, Peachy and Danny set off on an epic overland journey north beyond the Khyber Pass, "travelling by night and avoiding hostile Afghan villages", fighting off bandits, blizzards and avalanches, into the unknown land of Kafiristan (literally in the Afghan Dari languages means "Land of the (Non-Muslim) Infidels").
A few days later, Peachy and Danny happen upon a former Gurkha soldier who goes by the name Billy Fish (Saeed Jaffrey), the sole survivor of a mapping expedition several years before. Billy speaks English as well as the local tongue, and it is he, acting as translator and interpreter of the customs and manners, who smooths the path of Peachy and Danny as they begin their rise, first offering their services as military advisors, trainers, and war leaders to the chief of a much-raided village.
Peachy and Danny muster a force to attack the villagers' most-hated enemy. In their first battle, the natives decide that Danny must be a god when he is unharmed after being struck in the chest by an arrow. In fact, the arrow was stopped by a bandolier hidden beneath his clothing. As victory follows victory, the defeated warriors are recruited to join the swelling army.
Finally, there is no one left to stand in their way, and they are summoned to the holy city of Sikandergul. There, the head holy man sets up a re-enactment of the arrow incident, in order to determine whether he is a man or a god by seeing if he bleeds or not. When Danny flinches, the monks grab him and rip open his shirt, only to be stopped however, by Danny's Masonic Jewel (given to him for luck by fellow Mason Kipling). By coincidence, the symbol on the Jewel matches that of "Sikander" (Alexander the Great), who had passed through many centuries ago and promised to return. The holy men are convinced Danny is the reincarnation of Sikander. They hail him as king and lead the two men down to storerooms heaped with treasure (gold, silver, platinum, diamonds, rubys, emerals, etc.) that belonged to Sikander, which now belong to Danny.
As the months pass, Peachy is anxious to leave Kafiristan with all the treasure they can carry before winter closes the mountain passes to India (and before the natives learn the truth). However, Danny is against it however and develops delusions of grandeur as the power of god-king goes to his head (which will lead to the duo's downfall). First Danny suggests that Peachy bow to him like the others. Then he begins making plans to turn the land into a modern country, to the extent that he envisages eventually meeting Queen Victoria "as an equal". Disgusted, Peachy decides to take as much booty as he can carry on a small mule train, with his old friend's blessing.
Meanwhile, Danny decides to take a wife after seeing the beautiful Roxanne (Shakira), despite Peachy's strong warnings. Roxanne, having a superstitious fear that she will be struck dead if she consorts with a god, tries frantically to escape, biting Danny during the wedding ceremony. The bite draws blood, and when everyone sees it, they realise Danny is human after all.
The angry natives pursue him and Peachy as they attempt to escape from the city. Billy tries to buy time by courageously charging the mob singlehandedly with a Khukuri, but the pair are soon captured. Danny is forced to walk to the middle of a rope bridge over a deep gorge; he apologises to Peachy before the ropes are cut and he falls to his death. Peachy is crucified between two pine trees, but is cut down the next day when he survives the ordeal. Eventually, he makes his way back to India, though his mind has become unhinged by his sufferings.
As Peachy finishes his story, he presents Kipling with Danny's decomposing, severed head, still wearing its crown, thereby proving the tale is true.