Gabriel García Márquez, the Nobel Prize-winning Colombian writer who immersed the world in the powerful currents of magic realism, creating a literary style that blended reality, myth, love and loss in a series of emotionally rich novels that made him one of the most revered and influential writers of the 20th century, died April 17 at his home in Mexico City. He was 87.

The Associated Press reported his death. In July 2012, his brother Jaime García Márquez announced that the author had dementia.

Mr. García Márquez, who was affectionately known throughout Latin America as “Gabo,” was a journalist, novelist, screenwriter, playwright, memoirist and student of political history and modernist literature. Through the strength of his writing, he became a cultural icon who commanded a vast public following and who sometimes drew fire for his unwavering support of Cuban leader Fidel Castro.

In his novels, novellas and short stories, Mr. García Márquez addressed the themes of love, loneliness, death and power. Critics generally rank “One Hundred Years of Solitude” (1967), “The Autumn of the Patriarch” (1975) and “Love in the Time of Cholera” (1985) as his masterpieces.

“The world has lost one of its greatest visionary writers — and one of my favorites from the time I was young,” President Obama said in a statement, calling the author “a representative and voice for the people of the Americas.”

Mr. García Márquez established his reputation with “One Hundred Years of Solitude,” an epic novel about multiple generations of the Buendía family in the fantastical town of Macondo, a lush settlement based on the author’s birthplace on the Caribbean coast of Colombia. The novel explored social, economic and political ideas in a way that captured the experience of an entire continent, but it also included supernatural elements, such as a scene in which a young woman ascends to heaven while folding the family sheets.

By fusing two seemingly disparate literary traditions — the realist and the fabulist — Mr. García Márquez advanced a dynamic literary form, magic realism, that seemed to capture both the mysterious and the mundane qualities of life in a decaying South American city. For many writers and readers, it opened up a new way of understanding their countries and themselves.

In awarding Mr. García Márquez the literature prize in 1982, the Nobel committee said he had created “a cosmos in which the human heart and the combined forces of history, time and again, burst the bounds of chaos.”

“One Hundred Years of Solitude” has been translated into more than 35 languages and has sold, by some accounts, more than 50 million copies. The Chilean poet and Nobel laureate Pablo Neruda described the book as “the greatest revelation in the Spanish language since the Don Quixote of Cervantes.”

Mr. García Márquez parlayed his literary triumphs into political influence, befriending international dignitaries such as President Bill Clinton and François Mitterrand, the late president of France. The celebration for Mr. García Márquez’s 80th birthday was attended by five Colombian presidents and the king and queen of Spain.

Yet few knew the penury the author endured before achieving fame. “Everyone’s my friend since ‘One Hundred Years of Solitude,’ ” Mr. García Márquez once told a brother, “but no one knows what it cost me to get there.”

From ‘the House’ to the world

Gabriel José García Márquez was born March 6, 1927, in Aracataca, a town near Colombia’s Caribbean coast. He was the eldest child of a local beauty and a telegraph-operator-turned-itinerant-pharmacist — some called him a “quack doctor” — but Mr. García Márquez was raised mostly by his maternal grandparents, the pragmatic Col. Nicolás Márquez Mejía and the superstitious Tranquilina Iguarán Cote.

Mr. García Márquez later called the colonel, a veteran of two civil wars, “the most important figure in my life” and “my umbilical cord with history and reality.” They lived in a rambling complex of rooms and terraces, which Mr. García Márquez would often call simply “the House.”

The author had a charmed yet melancholy childhood. Aracataca once flourished under the banana business of the U.S.-based United Fruit Co. but slowly declined after December 1928, when more than 1,000 striking banana workers in nearby Ciénaga were massacred by the Colombian army. Macondo, the town in “One Hundred Years of Solitude,” was named after a United Fruit plantation.

Eventually, Mr. García Márquez was reunited with his parents and siblings in Sucre, a river settlement in Colombia that became the setting for some of his darkest books.

He escaped by winning a scholarship to a secondary school near Bogotá, the capital of Colombia. After graduating in 1946, he enrolled in law school at the National University of Colombia. Poor and rail-thin, he asserted himself through his literary prowess. Neglecting his classes, he devoted himself to reading and writing, publishing short fiction in the Bogotá newspaper El Espectador.

His literary endeavors were interrupted when the populist leader Jorge Eliécer Gaitán was assassinated in 1948. The killing led to days of rioting in Bogotá and marked the beginning of a period of political repression known as “La Violencia.” Within about 10 years, between 200,000 and 300,000 Colombians were killed.

When the riots caused the law school to close, Mr. García Márquez moved to Cartagena, where he launched a career in journalism. Later he would say that the assassination greatly influenced his understanding of politics.

During these years, the author was often so poor that he had no place to live. In Barranquilla, just up the coast from Cartagena, he found his first apartment: a cheap room in a brothel nicknamed “the Skyscraper.” He said this was the perfect environment for a writer — quiet during the day, the scene of a party every night.

It was not until 1954, when he joined the staff of the El Espectador, that he gained financial stability. The next year, he published his first novel, “Leaf Storm,” a tale about the burial of a reclusive doctor in Macondo. It went virtually unnoticed.

In 1955, he became El Espectador’s European correspondent, visiting the Eastern Bloc and studying at the Experimental Film Center of Cinematography in Rome between deadlines. He was on assignment in Paris when his newspaper was closed by the Colombian government.

Rather than return home, Mr. García Márquez remained in the French capital for two years, living hand to mouth while completing “No One Writes to the Colonel,” a glittering short novel about a war veteran who would rather starve than sell his fighting rooster. The story, published in 1961, was influenced by Hemingway’s “The Old Man and the Sea” and Italian director Vittorio De Sica’s neorealist films, such as “Umberto D.”

After returning to South America in 1957, Mr. García Márquez held a series of journalism jobs. He married his longtime fiancée, Mercedes Barcha, in 1958. He moved to Mexico in 1961, beginning one of the most disheartening and exhilarating periods of his life.

Mexican breakthrough

When he arrived in Mexico City, Mr. García Márquez had few friends and no prospects of work. He aimed for the movie industry, but when his family ran out of food, he took a job editing a women’s magazine and a crime magazine on the condition that his name would never appear in either. Later he landed jobs as a scriptwriter and as an advertising copywriter.

In his mid-30s, his ability to write fiction appeared to have dried up. His previous novel had been written in Paris, and he couldn’t seem to finish another. According to the Uruguayan critic Emir Rodríguez Monegal, who first met Mr. García Márquez around this time, he was “a tortured soul, an inhabitant of the most exquisite hell: that of literary sterility.”

Yet several important events occurred during his creative drought. First, Mr. García Márquez began reading the original magic realists: Mexican Juan Rulfo, Cuban Alejo Carpentier and Guatemalan Miguel Ángel Asturias, who would later win the Nobel Prize in literature. Next, he discovered the sophisticated Latin American novels that were being published in the movement known as “El Boom,” including those by the Mexican writer Carlos Fuentes, who embraced Mr. García Márquez as part of the group despite his lack of recent work.

One day in 1965, as Mr. García Márquez drove from Mexico City to Acapulco for a holiday weekend, everything changed. According to legend, he was navigating a twisting highway when the first sentence of “Solitude” suddenly formed in his mind:

“Many years later, as he faced the firing squad, Colonel Aureliano Buendía was to remember that distant afternoon when his father took him to discover ice.”

In that line’s mix of past and present, military and miraculous, lay the germ of the entire book.

For the next year, Mr. García Márquez did nothing but write while his wife pawned almost all their possessions to feed the family. “I didn’t know what my wife was doing, and I didn’t ask any questions,” he told an interviewer. “But when I finished writing, my wife said: ‘Did you really finish it? We owe $12,000.’ ”

Their financial gamble paid off. A few weeks after the novel’s publication in Buenos Aires, the couple visited the Argentine capital’s most prestigious theater. As they looked for their seats, the entire audience gave them a spontaneous standing ovation.

In Gerald Martin’s biography of Mr. García Márquez, journalist Tomás Eloy Martínez recalled: “At that precise moment, I saw fame come down from the sky, wrapped in a dazzling flapping of sheets, like Remedios the Beautiful, and bathe García Márquez in one of those winds of light that are immune to the ravages of time.”

Although magic realism had existed long before “Solitude” appeared, Mr. García Márquez’s version of it captivated readers because it was informed by both a gritty engagement with Latin American politics (thanks to his years in journalism) and an intimate knowledge of folkloric beliefs (thanks to his grandmother in Aracataca).

Its characters include both the Colonel Aureliano Buendía (father of 17 sons by 17 women, perpetrator of 32 uprisings and survivor of 14 assassination attempts) and the gypsy Melquíades, who can see the future and cast spells. Its plot includes a massacre of banana workers and a rainstorm that lasts four years, 11 months and two days. And its prose was a revelation: luminous, opulent, ecstatic.

The result, William Deresiewicz wrote in the Nation, is that Mr. García Márquez’s “impossible fusion of subject and tone gives utterance to the Latin American soul: by fronting the continent’s tragic history with the unquenchable fiesta of his style.”

Politics, patriarch and punch

In the years after that Argentine ovation, Mr. García Márquez transformed into an international celebrity. He moved from Mexico to Barcelona, where he socialized with all the major writers of El Boom. He became particularly close to the Peruvian novelist Mario Vargas Llosa, who named Mr. García Márquez the godfather of his second son.

Yet rifts in the friendship emerged in 1968 when the Cuban dissident Heberto Padilla was awarded a major literary prize against Castro’s wishes. The event proved a watershed moment for Latin American intellectuals. Most, including Vargas Llosa, supported Padilla and free speech. Mr. García Márquez supported Castro. When Castro imprisoned Padilla in 1971, the writers’ alliance cooled further.

The final break came in 1976, at a movie premiere in Mexico City. When Mr. García Márquez approached with an effusive, open-armed greeting (“Brother!”), Vargas Llosa punched him in the face. After the incident, rumors spread that there had been some impropriety with Vargas Llosa’s wife. (According to Martin, Mr. García Márquez’s most thorough biographer, the truth has never been uncovered.)

By that point, Mr. García Márquez was used to scandal. After Chile’s democratically elected government was overthrown by a military coup in 1973, he declared a literary “strike” to involve himself more directly in leftist politics.

His first move was to return to political journalism by co-founding­ the Colombian magazine Alternativa. His debut contribution was titled “Chile, the Coup, and the Gringos.” (The magazine was bombed the next year.)

His second move was to court the friendship of Castro. He decided, for instance, to write an article about Cuba’s military involvement in Angola and to submit the article to Castro for editing and approval before publication. Although the author’s meetings with Castro occasionally led to the release of Cuban prisoners, the Cuban dissident Reinaldo Arenas called Mr. García Márquez an “unscrupulous propagandist for communism who, taking refuge in the guarantees and facilities which liberty provides, set out to undermine it.”

Appropriately, the only novel Mr. García Márquez published during this period — “The Autumn of the Patriarch” (1975) — was a stunning meditation on the psychology and stratagems of power. Completed before his strike, the book portrays an unnamed tyrant who has been in power so long that no one can remember any other ruler. He ends up surrounded by people who tell him what he wants to hear but make fun of him behind his back.

Told in flashbacks in only 100 sentences, the book ranks among Mr. García Márquez’s most complex works. The novel, he declared, was “almost a personal confession, a totally autobiographical book” — a statement that has perplexed literary critics.

The great change

In 1980, after years of government pressure, Alternativa closed. The event marked the end of Mr. García Márquez’s overt political activism and his turn toward diplomacy and backroom mediation. It also cleared the way for his most electrifying literary period.

In 1981, he published “Chronicle of a Death Foretold,” a suspenseful and technically dazzling interpretation of the honor killing of his friend Cayetano Gentile in Sucre. Its opening print run (2 million copies) was the largest in history for a work of literary fiction.

Four years later, he brought out “Love in the Time of Cholera.” Partly based on his parents’ courtship, it tells the story of a man who loses the love of his youth but wins her back a half-century later, after her husband dies rescuing a parrot in a mango tree.

Then, in 1989, at the age of 62, Mr. García Márquez published “The General in His Labyrinth,” a meticulously researched novel about Simon Bolívar, the liberator of South America.

Still thriving at 71, he bought Cambio magazine in Colombia with a group of investors and conducted an interview with Venezuelan President Hugo Chávez. In 1999, he received a diagnosis of lymphoma and was seldom seen in public in the last decade of his life.

Survivors include his wife, two sons, seven brothers and sisters, and a half sister.

As Mr. García Márquez’s health and memory faded, so, inevitably, did his literary muscle. His last four books — “Of Love and Other Demons” (1994), “News of a Kidnapping” (1996), “Living to Tell the Tale” (2001) and “Memories of My Melancholy Whores” (2004) — are generally considered his weakest.

Meanwhile, the next generation of Latin American writers turned him into a symbol of the fiction and the politics they rejected. A 1996 anthology called “McOndo” suggested that his vision of a tragi-miraculous Caribbean countryside had no relevance in a world dominated by McDonald’s. The region’s next rising star, the Chilean novelist Roberto Bolaño, scorned his cozy relationship with power.

Yet even those rebellions proved Mr. García Márquez’s enduring influence. Three decades after the publication of “Solitude,” he was still the titan with whom every serious Latin American writer needed to reckon.

He forged Latin America’s most contagious and original style. He wrote its most influential and popular books about the motives of tyrants and the endurance of love. And he explained what connects his perennial themes: “You know, old friend, the appetite for power is the result of an incapacity for love.”

Valdes is a writer specializing in Latin American literature.