Thai Prime Minister Prayuth Chan-ocha, right, bows to statesman Prem Tinsulanonda in 2018 during a visit marking the traditional Thai New Year. (Panumas Sanguanwong/AFP via Getty Images)

Prem Tinsulanonda, who as an army commander, prime minister and adviser to the royal palace was one of Thailand’s most influential political figures over four decades, died May 26 at a hospital in Bangkok. He was 98.

His death was announced by the government’s Public Relations Department. Local media reported that the cause was heart failure.

Mr. Prem was best known for his long-standing devotion to the monarchy, especially the late King Bhumibol Adulyadej, who appointed him to his Privy Council immediately after Mr. Prem’s eight years as prime minister, and named him head of that powerful advisory body in 1998, a position he held until his death.

Mr. Prem is credited by some scholars with establishing the unspoken primacy of the palace in Thailand’s power structure, cementing a mutually beneficial alliance with the military.

He was prime minister from 1980 to 1988, and helped usher in a period of relative stability after a successful pro-democracy uprising against a military dictatorship in 1973, a counterrevolution and coup in 1976 and another coup in 1977, as well as edginess about communist takeovers in neighboring Vietnam in 1975.

Although most Thai army commanders came to the position through coups, Mr. Prem was elected constitutionally by parliamentary vote, but he never ran for office. As prime minister, he weathered two attempted coups and was reportedly the target of several assassination plots.

King Bhumibol Adulyadej, right, talks with Mr. Prem in 1981, during a visit to an irrigation project in northern Thailand. (Jeff Robbins/AP)

Critics questioned his devotion to democracy and accused him of encouraging, if not engineering, the 2006 coup that ousted elected Prime Minister Thaksin Shinawatra.

He denied such allegations, but in the months preceding the military takeover frequently talked about corruption and greed in government — a major accusation against Thaksin by his critics — and strongly advised in public speeches to army and navy cadets that their loyalty was to king and country, not the government.

Ironically, Mr. Prem’s barely veiled backing of the coup set in motion events that contributed to a decline in the near-universal respect for the monarchy, because of the perception among Thaksin’s supporters that the palace was taking sides in politics, something it publicly always denied doing under the system of constitutional monarchy.

“That coup was probably Prem’s last major political intervention, and it was one where he misjudged,” Kevin Hewison, a professor emeritus at the University of North Carolina and a veteran Thai studies scholar, said Sunday in an email. “He expected elation and praise for his open role in getting rid of Thaksin. Instead, his intervention lit the fuse of a political polarization that continues to haunt Thailand’s elite.”

The coup set off a sometimes violent battle for power between Thaksin’s opponents and his political allies, who despite electoral victories were forced time and again from office, culminating in another coup in 2014. An election in March was set to install a government in the near future, but constitutional changes ensure the military will keep elected politicians on a tight leash.

Mr. Prem greets British Prime Minister Margaret Thatcher in 1988. (Jeff Widener/AP)

Mr. Prem retained his role as a behind-the-scenes power broker after the 2006 coup, especially because King Bhumibol was in ill health for much of the decade before his death in 2016.

Mr. Prem was born in the major southern fishing port of Songkhla on Aug. 26, 1920. He attended the prestigious Chulachomklao Royal Military Academy in Bangkok and later U.S. Army schools. He began his military career in 1941 as a second lieutenant in a tank regiment.

He first achieved national prominence when he served as regional army commander in Thailand’s poor rural northeast from 1974 to 1977, during which he stressed rural development and civic action instead of military might in a successful campaign against communist insurgents. As prime minister, he continued using policies of amnesty and other political means to prompt defections from the communist guerrilla movement.

Junior officers pushed a reluctant Mr. Prem into taking the prime minister’s job in 1980, when Thailand was facing an ailing economy and perils on the border with Cambodia, occupied by Vietnamese forces who had driven out the communist Khmer Rouge regime and sent hundreds of thousands of refugees into Thailand. At the same time, Thailand expanded ties with China and Japan, and allies in the West and Southeast Asia.

Mr. Prem was appointed deputy interior minister in 1977 and later army commander and defense minister. He became prime minister in March 1980, after the resignation of Kriangsak Chamanand, another former military leader.

The border crisis with Cambodia eased over time, and Mr. Prem had the good luck to preside over the birth of Thailand’s economic boom, which ended only with Asia’s devastating 1997 financial crisis.

Thitinan Pongsudhirak, a political scientist at Bangkok’s Chulalongkorn University, credited Mr. Prem with keeping the military at arm’s length from politics by warding off the coup attempts in 1981 and 1985, and checking elected politicians from excessive graft by shielding the Finance Ministry and macro-policy agencies, particularly the Central Bank, from domestic politics.

But Mr. Prem showed little appetite for public political activity and was dubbed by some academics as suffering from “reluctant ruler syndrome.” Critics accused him of indecision and lacking in imagination, and influential business executives criticized his government’s austere economic policies. His aloof manner, bordering on arrogance, did not help his popularity.

“Prem disliked the cut-and-thrust of parliamentary politics, disdained elected politicians as the source of Thailand’s corruption and he seldom appeared in parliament,” said Hewison, the Thai studies scholar. “As prime minister, Prem established a system of government that has been a model for the current military junta.”

Mr. Prem never married and leaves no immediate survivors.

— Associated Press