W.P. Kinsella, author of “Shoeless Joe,” at a World Series game in Toronto in 1992. (Rusty Kennedy/AP)

W.P. Kinsella, a Canadian writer who published more than 25 books but who is best remembered in the United States for just one, “Shoeless Joe,” a magical exploration of baseball and fantasy in an Iowa cornfield that inspired the 1989 film “Field of Dreams,” died Sept. 16 in Hope, B.C. He was 81.

His literary agent, Carolyn Swayze, said in a statement that Mr. Kinsella’s death was doctor-assisted, a legal procedure in Canada since June. Other details were not disclosed, but he was known to have had serious complications from diabetes.

Before he turned to writing in the 1970s, Mr. Kinsella had a varied career, including working as a taxi driver, government clerk, insurance salesman and restaurant owner. He was 46 when his first novel, “Shoeless Joe,” in 1982.

The book may have been hard to classify — a magical realist fantasy touching on farming, a reclusive author, fathers and sons, dogged faith and, most of all, baseball — and it was not universally well received.

Yet “Shoeless Joe” became a literary phenomenon that would sell more than 1 million copies. In a review in the New York Times, writer Daniel Okrent described it as a “lyrical, seductive and altogether winning concoction.”

The tale follows the whimsical dreams of an Iowa farmer, Ray Kinsella, who looks out at his cornfield and, on the novel’s opening page, hears a voice say, “If you build it, he will come.”

Surprising his relatives and even himself, Kinsella plows up part of his corn crop to construct a baseball diamond, complete with lights, backstop and grandstand. He carefully tends the grass in left field, and after three years, a mystical apparition appears in an antiquated baseball uniform.

He has come.

The player is “Shoeless” Joe Jackson, one of the greatest players of his time and whose .356 career batting average that is still the third-highest in history. After emerging from the cornstalks and onto the Iowa field of dreams, Jackson invites teammates from the 1919 Chicago White Sox — infamously known as the “Black Sox” after the betting scandal that got them banished from baseball — to join him in a glorious romp of innocence.

But the players are not visible to everyone: Only those who trust in the magical powers of baseball and its ability to forge bonds across time have the ability to see Shoeless Joe. For those who believe, baseball becomes a faith as strong as any religion.

“A ballpark at night,” Mr. Kinsella writes, “is more like a church than a church.”

The story continues as another fateful voice intones, “Ease his pain.” Kinsella, the central character, interprets the cryptic command as a personal mission to find and kidnap the reclusive author J.D. Salinger, who accompanies him on a baseball road trip into the past. (After the actual Salinger threatened legal action, the character’s name was changed in the film adaptation to Terence Mann and was played by James Earl Jones.)

The novel includes a touching evocation of the two-inning career of a ballplayer named Moonlight Graham, who in real life became a small-town doctor.

Field of Dreams,” which starred Kevin Costner as Ray Kinsella and included Ray Liotta as Shoeless Joe and Burt Lancaster as Moonlight Graham, became a cultural phenomenon in its own right. It was filmed on a farm in Dyersville, Iowa, and the baseball diamond created in the cornfield became a destination for fans from around the world.

“I know there are many who are troubled, anxious, worried, insecure,” Mr. Kinsella wrote. “What is the cure? . . . The answer is in the word, and baseball is the word,”

William Patrick Kinsella was born May 25, 1935, in Edmonton. His parents were Americans who ended up in Canada during the Depression and stayed there. His father was a semiprofessional baseball player.

Mr. Kinsella grew up on a farm in Alberta without electricity or motorized vehicles. He didn’t attend school until he was 11, when his family settled in Edmonton. He held a variety of jobs in Edmonton and Victoria, including owning a pizzeria, before studying at the University of Victoria, from which he graduated in 1974. He received a master’s degree from the Iowa Writers’ Workshop at the University of Iowa in 1978. He taught at the University of Calgary from 1978 to 1983 and grew to detest academic life.

In 1977, Mr. Kinsella published a collection of humorous stories, “Dance Me Outside,” set on a Canadian Indian reservation, which became the basis of a 1994 film of the same title. His stories about Indian life were perhaps better known in Canada than his writings on baseball, but he was sometimes criticized for appropriating tribal folkways for humorous purposes.

Mr. Kinsella had a prickly personality — “more angry and cynical than I would ever make my characters” — and said his chief aim as a writer was to make money.

“I’m a manufacturer,” he said in 1993. “I’m in business to make my living as a writer.”

His marriages to Myrna Salls, Mildred Clay and Ann Knight ended in divorce. His fourth wife, Barbara Turner, died in 2012. Survivors include two daughters from his first marriage.

In the mid-1990s, Mr. Kinsella had a relationship with Canadian writer Evelyn Lau, who later wrote disparagingly about him. He sued for defamation before the case was settled out of court.

In addition to “Shoeless Joe,” Mr. Kinsella published several other books about baseball and small-town life, including “The Iowa Baseball Confederacy,” “Box Socials” and “The Dixon Cornbelt League.” In 1997, he sustained serious injuries after being struck by a car while walking and was unable to write for several years. In 2011, he published his final novel, “Butterfly Winter,” about twin baseball-playing brothers in Central America.

He recognized that his signature achievement would always be “Shoeless Joe,” with its lyrical look at baseball, family bonds and America.

“I swear the stars have moved in close enough to eavesdrop as I sit in this single rickety bleacher that I built with my unskilled hands, looking down at Shoeless Joe Jackson,” Mr. Kinsella wrote.

“ ‘God what an outfield,’ he says. ‘What a left field.’ He looks up at me and I look down at him. ‘This must be heaven,’ he says.

“ ‘No. It’s Iowa.’ ”