Mark Merlis, who debuted as a novelist in his 40s, penning four works of fiction that explored the joys, tensions and agonies of gay life in America in the 20th century, died Aug. 15 at a hospital in Philadelphia. He was 67.

The cause was pneumonia associated with amyotrophic lateral sclerosis, the neurological disease also known as Lou Gehrig’s disease, said his husband, Robert Ashe.

For much of his adult life, Mr. Merlis earned his livelihood providing health-care analysis for the Library of Congress’s Congressional Research Service and, later, as an independent consultant. But since his youth, he had harbored literary ambitions he ultimately realized with the publication of his first novel, “American Studies,” in 1994.

With that book and the three that followed, Mr. Merlis was widely praised for the sensitivity with which he addressed such themes as the corrosive effect of shame and the intersecting paths of past and present.

“I am, of course, a gay man whose . . . novels are swarming with gay characters,” he once told an interviewer with the website EchoNYC. “And I have allowed myself to be marketed as a practitioner of a genre called gay fiction. But this is a commercial category, not an artistic one. I write, like anybody else, about how it is to be human.”

“I always thought being a writer was the highest calling there was,” novelist Mark Merlis said. “Don’t you?” (Robert Ashe)

“American Studies” featured an aging gay narrator, Reeve, who is severely assaulted by a hustler. As he convalesces, Reeve remembers his beloved English teacher — a character modeled on the Harvard scholar F.O. Matthiessen — who is outed as gay and commits suicide against the backdrop of U.S. Sen. Joseph R. McCarthy’s (R-Wis.) communist witch hunt in the 1950s. A reporter for Newsday described the book as “one of the best gay novels of the decade.”

Mr. Merlis’s second book, the wildly imaginative “An Arrow’s Flight” (1998), moved the Philoctetes story of Sophocles from the Trojan War to the modern day, inflicting its protagonist with AIDS instead of a stigmatic snake bite. “We get gods and goddesses, aircraft carriers and archaic armor, high priests and go-go boys,” the author Christopher Bram wrote of the work.

The novel received a Lambda Literary Award and was voted one of the best gay novels of all time by Publishing Triangle, an organization of 250 gay and lesbian writers, editors and publishing professionals.

Mr. Merlis’s third book, “Man About Town” (2003), was described as his most autobiographical work. The protagonist, who is gay, is a government health-care analyst and finds himself assigned to work on legislation that would deny benefits to AIDS patients who contract the disease through gay relationships or drug use. Meanwhile, he searches for the unnamed bathing-suit model who had first awakened his sexual desires when he was young.

Despite the book’s serious subject matter, it showcased Mr. Merlis’s humor. The protagonist sees the denizens of Capitol Hill as “white guys with bad comb-overs, voting silently in the middle of the night while C-Span played Vivaldi.” One particularly unimpressive senator, after introducing an amendment he failed to grasp, “had the relieved look of a school kid who has delivered his book report without throwing up.”

“The hero is just close enough to the action to know that something is going on, but not close enough to know just what that something is,” Mr. Merlis once told Bram in an interview, reflecting also on his own career in government. “That was how it felt for me in my Washington years: I got to go to a lot of closed meetings at which decisions seemed to be made, but I was never in the pre-meeting at which the principals actually made up their minds.”

Mr. Merlis’s final book, “JD” (2015), featured the intertwining narration of a widow and her late husband, who is revealed in his posthumously discovered diaries as bisexual. Taken together, Bram wrote in a tribute, Mr. Merlis’s books “explore American life with the insight and power of the best work of James Baldwin and Philip Roth.”

Mark Lane Merlis was born in Framingham, Mass., on March 9, 1950. His father was a doctor, and his mother was a homemaker.

Mr. Merlis grew up in Baltimore — in what he called the “Cheeveresque northern section called Roland Park” — before attending Wesleyan University in Middletown, Conn., where he received a bachelor’s degree in English in 1971. Five years later, he received a master’s degree in American studies from Brown University.

“I mostly just spent my college years brooding about those unwelcome queer feelings that I couldn’t shake off,” he told Bram.

After college, Mr. Merlis said, he “tumbled into the bureaucratic life that ensnared me for the next 35 years.” He worked for the Maryland health department and later for the federal government in the 1980s and 1990s, including on the Ryan White Care Act of 1990 that provided funding for HIV/AIDS services.

At the time of his death, Mr. Merlis lived in Philadelphia. Survivors include his partner of 35 years, Ashe, whom he married in 2014, of Philadelphia; and two brothers.

“I always thought being a writer was the highest calling there was,” Mr. Merlis said. “Don’t you?”