A 1962 portrait of E.R. Braithwaite, author of “To Sir, with Love,” by Carl Van Vechten. (Carl Van Vechten Collection/Library of Congress, Prints & Photographs Division)

E.R. Braithwaite, a Guyanese author whose book about his experiences as a black man teaching in a largely white school in London, “To Sir, With Love,” became a bestseller and inspired a popular 1967 film starring Sidney Poitier, died Dec. 12 at a hospital in Rockville, Md. He was 104.

He lived in Washington and died of a “cardiac-related event,” said his companion, Genevieve “Ginette” Ast.

Mr. Braithwaite was a World War II veteran and trained as a physicist at the University of Cambridge. But, as a black man from what was then the colony of British Guiana, he had difficulty finding work in his field in the early 1950s.

“I was too black to be a scientist,” he once said, “and too educated to be a lot of other things.”

He wrote in his 1972 book “Reluctant Neighbors” that his hopes dwindled, “bit by bit, day by day, into weeks and months, until the only place on the whole arid horizon was a mangy schoolhouse beside a bomb-racked, rotting graveyard, and a smelly classroom with forty-six foul-mouthed youngsters.”

His students at St. George’s in the East — changed to Greenslade Secondary School in “To Sir, With Love” — were a tough lot who had grown up in poverty during and after World War II. Most of them were white. He was the only black teacher on the faculty.

The school was a laboratory of progressive educational ideas, with corporal punishment strictly prohibited — even though the students were unruly, noisy and coarse.

In Mr. Braithwaite’s somewhat fictionalized account, which was published in Britain in 1959 and in the United States a year later, the students ignore him in the classroom, curse and slam their desktops as he speaks. Couples neck openly in the halls.

Raising his voice, Mr. Braithwaite tells the students he expects them to act like “ladies and gentlemen.” He imposes a sense of discipline and decorum on his class by insisting that girls be addressed as “Miss” and the boys by their last names.

He becomes known simply as “Sir.”

When one boy says he knows the girls too well to be so formal, Mr. Braithwaite responds, “Is there any young lady present whom you consider unworthy of your courtesies?”

A turning point comes during a gym class, when the boys pair off to practice boxing. The one boy without a partner is the ringleader of the ruffians. Mr. Braithwaite reluctantly puts on boxing gloves and, after being stuck in the face, knocks the wind out of the student. He then helps the boy to his feet, and they form a grudging respect.

He deviates from the standard curriculum to discuss serious issues with the students: poverty, sex, love and death. After some prodding, the entire class attends the funeral of the mother of a black student. The book also describes Mr. Braithwaite’s growing romantic attachment to a white teacher.

At the end of the year, the students give Mr. Braithwaite a parting gift of 100 monogrammed cigarettes — even though he didn’t smoke — with a note: “To Sir, with love.”

During his seven years of teaching, Mr. Braithwaite kept meticulous daily notes, recording which tactics seemed most beneficial in the classroom. After he resigned to work for London’s welfare agency, he was about to throw out the notes when a fellow teacher suggested that he write a book, based on his experiences.

“It is a book that one devours quickly,” novelist John Wain wrote in a review for the New York Times, “but ponders slowly, and forgets — if I may risk the prediction — not at all.”

Some of Mr. Braithwaite’s former students and fellow teachers questioned the accuracy of his account. Nevertheless, “To Sir, With Love” was translated into more than 25 languages and made his reputation as an author.

Writer and director James Clavell adapted it for film, with Academy Award-winner Poitier in the lead role, renamed Mark Thackeray in the screen version. The movie’s theme song, sung by Lulu, who also had a role as one of the students, became a No. 1 hit in the United States.

Mr. Braithwaite said he believed the movie adaptation took too many liberties with his book.

“I detest the movie from the bottom of my heart,” he said in 2007. “I don’t like it because the movie is about the classroom, while my book is about my life.”

Eustace Edward Ricardo Braithwaite was born June 27, 1912, in Georgetown, British Guiana (now the country of Guyana). His parents were Oxford-educated intellectuals, and his father dealt in gems and precious metals.

He studied in New York City during the 1930s and served in Britain’s Royal Air Force during World War II. He received a master’s degree in physics from Cambridge in 1949.

In 1960, he moved to Paris, where he worked as a human rights official for a veterans organization and later as a consultant to the United Nations’ educational and cultural division, UNESCO.

He had brief stints as Guyana’s representative to the United Nations and as his country’s ambassador to Venezuela. He lived in New York before settling in Washington in 1996. He taught at a number of colleges, including Howard University.

Besides “To Sir, With Love,” Mr. Braithwaite published several other novels and volumes of memoirs. His books were banned for many years in South Africa. When he traveled throughout the country, he was granted the official status of “Honorary White,” which became the title of a 1975 account of his visit.

One subject he did not write about was his mixed-race marriage, unusual in Britain in the 1940s, to Sibyl Allen. They had five children before they were divorced.

In addition to Ast, his companion of Washington, survivors include two sons from his marriage, Ronald Braithwaite of Harrowgate, England, and Francis Braithwaite of London; five grandchildren; and two great-grandchildren. Three of his children predeceased him.

At 101, Mr. Braithwaite returned to Britain to attend new theatrical productions of “To Sir, With Love.”

“Those kids in the East End made a great impression on me,” he told the Glasgow Herald in 2013. “It struck me one day that the children didn’t have any respect for themselves, and this was why they had no respect for other people and I seized upon that idea. I challenged them to respect themselves.”