Gore Vidal, a celebrated writer, cul­tural gadfly and occasional political candidate, died July 31 at his home in Hollywood Hills, Calif., at 86. He had complications from pneumonia, his nephew, the actor, director and screenwriter Burr Steers, told the Associated Press.

Known for his urbanity and wit — “Every time a friend succeeds, I die a little”; “A narcissist is someone better looking than you are” — Mr. Vidal enjoyed a literary career that spanned more than 60 years, and he once said that he hoped to be remembered as “the person who wrote the best sentences of his time.”

Mr. Vidal was an astonishingly versatile man of letters and nearly the last major writer of the modern era to have served in World War II. Having resolved at age 20 to live by his pen, he wrote plays for television and Broadway, including the classic political drama “The Best Man”; helped script such movies as “Ben-Hur,” the 1959 epic starring Charlton Heston; and gained notoriety for the campy 1968 novel “Myra Breckinridge,” about a transsexual film enthusiast.

Mr. Vidal also won plaudits from scholars, critics and ordinary readers for historical novels such as the best-selling “Julian” (1964), “Burr” (1973) and “Lincoln” (1984). “United States,” which gathers Mr. Vidal’s essays on art, politics and himself, received the 1993 National Book Award.

In print or on television — he was a frequent talk-show guest — the worldly Mr. Vidal provoked controversy with his laissez-faire attitude toward every sort of sexuality, his well-reasoned disgust with what he called American imperialism and his sophisticated cynicism about love, religion, patriotism and other sacred cows.

He took an acerbic view of American leadership. “Today’s public figures can no longer write their own speeches or books,” he once quipped, “and there is some evidence they cannot read them either.”

As a boy, a thirst for learning

Mr. Vidal was born Oct. 3, 1925, at West Point, N.Y., where his father, Eugene Vidal, was teaching aeronautics at the military academy. His mother, Nina, was the socialite daughter of Sen. T.P. Gore of Oklahoma. Christened Eugene Luther Gore Vidal, the future writer later lopped off the first two names “for political as well as for aesthetic reasons.”

Young Gore spent much of his childhood in Washington and was particularly attached to his grandfather. The senator was blind, so the boy passed many hours reading to him aloud, thus inaugurating his own lifelong passion for learning and books. “The first grown-up book that I read on my own was a nineteenth-century edition of ‘Tales from Livy’ that I’d found in my grandfather’s library,” he once wrote. By 14, he added, “I wanted to know the entire history of the entire world.”

Mr. Vidal attended the private St. Albans School in Washington, where he fell in love with a fellow student named Jimmie Trimble, who was killed in combat on Iwo Jima during World War II. In his memoirs “Palimpsest” (1995) and “Point to Point Navigation” (2006), Mr. Vidal makes clear that this youthful passion marked his entire life: He never truly loved anyone again, although he would enjoy hundreds of sexual encounters, many of them with anonymous strangers, in which he took pleasure but, as he repeatedly insisted, never gave any except inadvertently.

Although Mr. Vidal maintained a more than 50-year partnership with his companion, Howard Austen, he constantly underscored that the secret of its longevity was “no sex.” Austen died in 2003.

As a teenager, Mr. Vidal was sent to boarding school at Phillips Exeter Academy in New Hampshire, from which he graduated in 1943. Rather than go on to Harvard, he enlisted in the Army, serving as first mate on a small supply ship in the Aleutians. That experience inspired his widely praised first novel, “Williwaw,” which appeared in 1946, when the author was 20.

Influence on stage and screen

After his discharge, Mr. Vidal decided to bag college and live in New York as a full-time writer. Before long, he became an intimate confidant of diarist Anais Nin and a friend of playwright Tennessee Williams. He also brought out two more novels, including “The City and the Pillar” (1948), an account of two all-American boys and what was — at that time — “the love that dare not speak its name.”

Although that book is now viewed as a pioneering work of gay literature, its casual acceptance of homosexual impulses offended some contemporary critics — and Mr. Vidal’s subsequent seven novels went unnoticed by Time magazine, Newsweek and the New York Times.

Because most of his fiction of the 1950s — even now admired works such as “Messiah” (1954), the study of a religious cult — proved commercially lackluster, Mr. Vidal decided to earn his living by writing TV dramas, Broadway plays and movie scripts. He also cranked out three mysteries under the pen name Edgar Box.

With the money from his commercial writing, Mr. Vidal paid the mortgage on a grandly pillared Greek Revival manse called Edgewater, located on the banks of the Hudson River near Rhinecliff, N.Y. There, he threw parties attended by rising literary notables such as Saul Bellow and Norman Mailer, critics Lionel and Diana Trilling, and movie stars Joanne Woodward and Paul Newman (who became his close friends).

Although Mr. Vidal enjoyed a varied social and sexual life, he nonetheless worked hard. On Broadway he hit pay dirt with “Visit to a Small Planet” (1957), in which an alien named Kreton lands on Earth and announces that human beings are his hobby. It deftly skewers contemporary mores and Cold War anxieties.

The even more highly regarded political drama “The Best Man” (1960), which was nominated for a Tony Award as best play, presented a behind-the-scenes look at the wheeling and dealing between two men competing for the Democratic presidential nomination. Both plays became films and have periodically been revived on stage.

As a screenwriter in the 1950s and occasionally afterward, Mr. Vidal contributed to many films, often without screen credit. He wrote a teleplay that inspired “The Left-Handed Gun”(with Newman as Billy the Kid); he was called in to doctor “Ben-Hur”(and tweaked the script to suggest a homosexual subtext to explain the relationship between the epic’s hero and his enemy Messala); and he worked with Williams on the hothouse melodrama “Suddenly, Last Summer.”

In his later years, Mr. Vidal appeared with some frequency in films, notably as himself in Federico Fellini’s “Roma” (1972) and as a U.S. senator in Tim Robbins’s “Bob Roberts” (1992).

By the early 1960s, the not-yet-40-year-old Mr. Vidal had achieved his goal of financial independence. For the next three decades, he spent much of his life in Italy, his villa a lodestone for literati and glitterati. There he carefully researched his novel “Julian” — about the apostate Roman emperor — and its success relaunched his moribund career as a fiction writer.

In general, the older Mr. Vidal published three kinds of fiction: historical novels set in the ancient world, such as “Julian” and 1981’s “Creation” (which features Socrates, Zoroaster, the Buddha and Confucius); campy fantasies that mock American prejudices and conventionalities, the most famous of which is “Myra Breckinridge”; and the so-called American Chronicle, a series of seven novels — the best known are “Burr” and “Lincoln” — detailing the secret political history of the United States.

In these years, Mr. Vidal also grew more prominent as a pundit, on TV and in the pages of the New York Review of Books and other periodicals. Although he had published essays and reviews since the 1950s, Mr. Vidal increasingly cast himself as a modern-day Voltaire, commenting on the nation’s follies with waspish asperity and wit.

“There is no human problem which could not be solved if people would simply do as I advise,” he said. He insisted that everyone is really bisexual: “There is no such thing as a homosexual or a heterosexual person. There are only homo- or heterosexual acts. Most people are a mixture of impulses if not practices.” Political elections, he observed, were “held at great cost without issues and with interchangeable candidates.”

Most famously, during the heated days of the national conventions of 1968, Mr. Vidal squared off on the issue of freedom of speech with conservative pundit William F. Buckley Jr. The pair ended up trading insults: “Crypto-Nazi,” Mr. Vidal said. “You queer,” Buckley shot back.

Mr. Vidal collected the best of his discursive prose in “United States” (1993), a mammoth volume of literary essays, political polemics and autobiographical reminiscences for which he received the National Book Award. Although it included a scandalously frank account of the Kennedys entitled “The Holy Family,” Mr. Vidal’s finest pieces were not his attacks but his appreciations.

He produced exemplary reappraisals — composed in ballpoint pen on yellow legal pads — of his favorite childhood authors (notably L. Frank Baum, creator of the “Oz” books) and of many once-undervalued figures, such as Dawn Powell, Italo Calvino, William Dean Howells, Thomas Love Peacock and Logan Pearsall Smith.

That some of these writers continued to be neglected only supports Mr. Vidal’s frequent lament: The age of the reader is passing, and we are living through its twilight’s last gleaming.

The occasional politician

Although Mr. Vidal found success as a writer and intellectual, he failed in his attempts to win political office. He twice ran unsuccessfully in elections, campaigning for Congress in 1960 and then for the Senate in 1982. While politics was in his view always corrupt, he also felt it had grown more so since World War II.

“I date the end of the old republic and the birth of the empire to the invention, in the late thirties, of air conditioning,” he said. Before air conditioning, “the politicians would abandon Washington in the summer; now they stay around all through the year, making mischief.”

In his later years, Mr. Vidal grew less witty and increasingly vehement in his political views, speaking out against American policy after the Sept. 11, 2001, terrorist attacks and denouncing the 2003 invasion of Iraq.

Mr. Vidal once pointed out that his literary genealogy included “Petronius, Juvenal, Apuleius — then Shakespeare — then Peacock, Meredith, James, Proust.” Like those cultivated and polished writers, Mr. Vidal cast a cold eye on the society of his time and resolutely upheld the values of urbanity and pleasure against the onslaughts of the barbarian, the puritan and the philistine.

“Always a godfather, never a god,” he once remarked at a christening.

style@washpost.com

Dirda reviews books each Thursday in Style and conducts a book discussion for The Post at wapo.st/reading-room.