Major Scobie lives in a colony in the West Coast of Africa during World War II, and is responsible for local security during wartime. His wife Louise, an unhappy, solitary woman who loves literature and poetry, cannot make friends. Scobie feels responsible for her misery, but does not love her. Their only child, Catherine, died in England several years before. Louise is a devout Catholic. Scobie, a convert, is also devout. Scobie is passed over for promotion to Commissioner, which upsets Louise both for her personal ambition and her hope that the local British community will begin to accept her. Louise asks Scobie if she can go and live in South Africa to escape the life she hates.
At the same time, a new inspector, named Wilson, arrives in the town. He is priggish and socially inept, and hides his passion for poetry for fear of ostracism by his colleagues. He and Louise strike up a friendship, which Wilson mistakes for love. Wilson rooms with another colleague named Harris, who has created a sport for himself of killing the cockroaches that appear in the apartment each night. He invites Wilson to join him, but in the first match, they end up quarrelling over the rules of engagement.
One of Scobie's duties is to lead the inspections of local passenger ships, particularly looking for smuggled diamonds, a needle-in-a-haystack problem that never yields results. A Portuguese ship, the Esperança (the Portuguese word for "hope"), comes into port, and a disgruntled steward reveals the location of a letter hidden in the captain’s quarters. Scobie finds it, and because it is addressed to someone in Germany, he must confiscate it in case it should contain secret codes or other clandestine information. The captain says it’s a letter to his daughter and begs Scobie to forget the incident, offering him a bribe of one hundred pounds when he learns that they share a faith. Scobie declines the bribe and takes the letter, but having opened and read it through (thus breaking the rules) and finding it innocuous, he decides not to submit it to the authorities, and burns it.
Scobie is called to a small inland town to deal with the suicide of the local inspector, a man named Pemberton, who was in his early twenties and left a note implying that his suicide was due to a loan he couldn’t repay. Scobie suspects the involvement of the local agent of a Syrian man named Yusef, a local black marketeer. Yusef denies it, but warns Scobie that the British have sent a new inspector specifically to look for diamonds; Scobie claims this is a hoax and that he doesn't know of any such man. Scobie later dreams that he is in Pemberton's situation, even writing a similar note, but when he awakens, he tells himself that he could never commit suicide, as no cause is worth the eternal damnation that suicide would bring.
Scobie tries to secure a loan from the bank to pay the two hundred pound fee for Louise’s passage, but is turned down. Yusef offers to lend Scobie the money at four percent per annum. Scobie initially declines, but after an incident where he mistakenly thinks Louise is contemplating suicide, he accepts the loan and sends Louise to South Africa. Wilson meets them at the pier and tries to interfere with their parting.
Shortly afterwards, the survivors of a shipwreck begin to arrive after forty days at sea in lifeboats. One young girl dies as Scobie tries to comfort her by pretending to be her father, who was killed in the wreck. A nineteen-year-old woman named Helen Rolt also arrives in bad shape, clutching an album of postage stamps. She was married before the ship left its original port and is now a widow, and her wedding ring is too big for her finger. Scobie feels drawn to her, as much to the cherished album of stamps as to her physical presence, even though she is not beautiful. She reminds him of his daughter.
He soon starts a passionate affair with her, all the time being aware that he is committing a grave sin of adultery. A letter he writes to Helen ends up in Yusef's hands, and the Syrian uses it to blackmail Scobie into sending a package of diamonds for him via the returning Esperança, thus avoiding the authorities.
After Louise unexpectedly returns, Scobie struggles to keep her ignorant of his love affair. But he is unable to renounce Helen, even in the confessional, where the priest instructs him to think it over and postpones absolution. Still, to placate his wife, Scobie attends Mass with her and receives communion in his state of mortal sin—a sacrilege according to Catholic teaching. Soon after Yusef's servant delivers a 'gift' to Scobie, which he refuses; however, Scobie's servant, Ali, witnesses this and a romantic embrace between Scobie and Helen. Scobie visits Yusef to confront him about the gift but more so to unburden his suspicion that Ali, whom he had trusted for all of their 15 years together, is disloyal. Yusef says he will take care of the matter, which within a few hours ends up in Ali being killed by local teenagers known as "wharf rats." The reader is led to believe that Yusef arranged the killing; however, Scobie blames himself.
Having gone this far down the path of ruin and seeing no way out, the proud Scobie decides to free everyone from himself—including God—and plots his death by faking a heart ailment and getting a prescription for sleeping pills. Knowing full well that suicide is the ultimate damnation according to church doctrine, he proceeds in the end to commit suicide with the pills. The act, however, yields ambiguous results. Helen continues her dreary existence. And Louise, who knew about the affair all along, is made to realize by her suitor, Wilson, that Scobie’s death was a suicide. She tells Wilson she won’t marry him but might in time.
The concluding chapter consists of a short encounter between Louise and the confessional priest. Louise tries to square Scobie’s suicide with his Catholicism, to which the priest advises that no one can know what’s in a person’s heart or about God’s mercy.