Lee Kuan Yew, whose efficient but often heavy-handed leadership helped transform Singapore from a chaotic British colonial backwater into one of the world’s most prosperous and orderly states, died March 23 in a Singapore hospital. He was 91.

Mr. Lee had been hospitalized with pneumonia since February. The prime minister’s office announced the death.

As prime minister from 1959 to 1990, Mr. Lee ushered Singapore through independence from Britain, a merger and subsequent breakup with neighboring Malaysia, and a period of explosive racial tensions before turning the Southeast Asian city-state into one of the region’s economic “tigers.” By the time he stepped down after 31 years at the helm, he was the longest-serving prime minister in the world.

Mr. Lee then held senior advisory posts in the cabinets of two of his successors, including his eldest son, until he resigned in May 2011. In all, he spent 52 years in government, presiding over Singapore’s rise as one of the globe’s leading financial centers and busiest ports, with GDP per capita ranked third in the world. Even after relinquishing power, he maintained outsize influence, sought for his counsel on matters ranging from how to achieve political stability and economic growth to ways of dealing with China.

His bluntness sometimes got him into trouble, notably when he lectured other countries publicly or when his private comments to U.S. officials became public. According to a U.S. diplomatic cable released by the anti-privacy group WikiLeaks, Mr. Lee in 2007 said dealing with Burma’s military junta was like “talking to dead people.” In 2009, in another leaked cable, he apparently called North Korean officials “psychopathic types, with a ‘flabby old chap’ for a leader who prances around stadiums seeking adulation.”

Scarred by deadly race riots that rocked Singapore in the 1960s, Mr. Lee took far-reaching steps to tamp down racial and religious tensions among the teeming island state’s Chinese, Malay and Indian populations. He imposed integration, instituting strict rules to ensure that Singaporeans of different backgrounds lived, studied and worked together.

A British-educated lawyer by training, Mr. Lee ran a government that was widely regarded as farsighted, honest and efficient, but it also could be overbearing and patronizing. The result was a tidy, law-abiding country, but one that visitors often described as regimented, sterile and dull.

Critics also charged that Mr. Lee’s administration permitted detention without charge or trial, censored the press, harassed political opponents and turned a blind eye to police mistreatment of suspects.

Some Singaporeans complained that the avowedly “paternalistic” government treated them like children, forbidding private citizens to own home satellite dishes, fining and humiliating people caught failing to flush public toilets, and even imposing a nationwide ban on chewing gum.

When a BBC reporter once suggested to him that allowing people to chew gum could help spur creativity, Mr. Lee retorted: “If you can’t think because you can’t chew, try a banana.”

Mr. Lee steadfastly defended his tough approach to political opponents, arguing that it was imperative in a country such as Singapore, with its ethnic Chinese majority and sizable Malay and Indian minorities.

“Nobody doubts that if you take me on, I will put on knuckle-dusters and catch you in a cul-de-sac,” he was quoted as saying in “Lee Kuan Yew: The Man and His Ideas,” a 1997 biography. “If you think you can hurt me more than I can hurt you, try. There is no other way you can govern a Chinese society.”

Harry Lee Kuan Yew was born Sept. 16, 1923, in Singapore, then a British colony, where his great-grandfather had emigrated from China’s Guangdong province in 1862. His father, Lee Chin Koon, was a storekeeper and worked for Shell Oil as a depot manager. His mother, Chua Jim Neo, was the daughter of a wealthy businessman and became a renowned cooking teacher.

For the first three decades of his life, Mr. Lee was known mostly as Harry Lee, but he dropped the Anglicized first name as his political career blossomed.

He studied at Raffles College in Singapore, but his higher education plans were interrupted by the outbreak of World War II and the Japanese invasion of Singapore. Mr. Lee learned to speak Japanese and found work as a translator and editor for the occupiers’ propaganda department.

The 1942-1945 occupation had a profound impact on the young Mr. Lee, who recalled in his memoirs being slapped and forced to kneel for failing to bow to a Japanese soldier. He and other young Singaporeans “emerged determined that no one — neither Japanese nor British — had the right to push and kick us around,” he said later. “We determined that we could govern ourselves.”

The occupation also drove home lessons about raw power and the effectiveness of harsh punishment in deterring crime, he wrote in his memoirs.

After the war, Mr. Lee earned a law degree from the University of Cambridge, where he courted Kwa Geok Choo, a fellow law student he had met in Singapore. They married secretly in London in 1947, then again more formally in 1950 after returning to Singapore, where they set up a law practice together.

The couple had two sons — Lee Hsien Loong, who became prime minister in 2004, and Lee Hsien Yang, chairman of the Civil Aviation Authority of Singapore since 2009 — and a daughter, Lee Wei Ling, who heads the National Neuroscience Institute. They survive, along with seven grandchildren. Kwa died in 2010 at 89.

In 1954, Mr. Lee and a group of other British-educated Singaporeans formed the People’s Action Party (PAP) as a populist, socialist organization seeking independence from Britain, which had reoccupied its colony after the war. The following year, he won a legislative seat that he would continue to hold for more than five decades. He became Singapore’s first prime minister in 1959, presiding over a government that was autonomous except in defense and foreign affairs.

In 1961, neighboring Malaya proposed a merger in which Singapore would join a new Federation of Malaysia, which Mr. Lee enthusiastically endorsed, seeing it as a way to ensure the political and economic viability of his tiny, resource-poor island. Voters backed him in a referendum, and, on Aug. 31, 1963, Mr. Lee declared independence from Britain, paving the way for Singapore to join the federation.

Race riots in 1964, in which at least 34 people were killed and more than 560 were injured in clashes between Chinese and Malays, exacerbated a political dispute between Mr. Lee’s PAP and Malaysia’s ruling United Malays National Organization. Eventually, Malaysian Prime Minister Tunku Abdul Rahman moved to expel Singapore from the federation.

Displaying rare emotion, Mr. Lee wept on national television as he announced Singapore’s separation from Malaysia in August 1965, declaring it a “moment of anguish” for him that “literally broke everything that we stood for.”

As a result, Singapore gained full independence — the only country in modern history to do so against its will.

Mr. Lee set about building Singapore, adopting free-trade and business-friendly policies. He cracked down hard on corruption, launched urban reforms, bulldozed squalid slums and enforced multiculturalism in an effort to create a uniquely Singaporean identity.

To prevent the formation of what it called “racial enclaves,” his government crafted elaborate rules stipulating the percentages of Chinese, Malays and Indians who could live in public housing projects. “We cannot allow segregation,” Mr. Lee declared.

At the same time, Mr. Lee showed little tolerance for dissent. Saying that Singapore “has always to be a tight ship,” he made free use of the Internal Security Act, a law predating independence that allows for arrest and detention without trial.

The case of Chia Thye Poh illustrated Mr. Lee’s penchant for political vindictiveness. Chia, a mild-mannered former physics teacher and member of parliament from a socialist opposition party, was arrested in 1966 and spent 23 years in prison without charge or trial, becoming one of the world’s longest-held political prisoners. The government suspected him of being an undercover communist agitator, which Chia emphatically denied, and he stubbornly refused to sign a confession in return for his freedom.

Chia was released in 1989, but Mr. Lee’s government then imposed a bizarre form of internal exile off Singapore’s main island. He was confined to a small former guardhouse on Sentosa Island, a resort that is the city-state’s equivalent of Disneyland. It was not until 1998 that authorities lifted all restrictions on him.

“They wanted me to pay a very high price for not kowtowing to them,” Chia said.

Mr. Lee was unapologetic. “We have to lock up people, without trial, whether they are communists, whether they are language chauvinists, whether they are religious extremists,” he said in 1986. “If you don’t do that, the country would be in ruins.”

Critics also accused Mr. Lee of using Singapore’s libel laws to suppress dissent by suing political opponents into bankruptcy. One who made that charge was Devan Nair, who served as president of Singapore in the early 1980s before falling out with Mr. Lee and moving to Canada, where he died in 2005. From exile, Nair described Mr Lee as an “increasingly self-righteous know-all” whose acolytes were “department store dummies.” Mr. Lee later sued his former comrade for libel in Canada but eventually dropped the case.

A bigger target of Mr. Lee’s wrath was Workers’ Party leader J.B. Jeyaretnam, a gadfly who in 1981 became the first opposition politician to win a seat in Parliament since independence. He was repeatedly sued for slander or libel over the years. After failing to keep up with payments for damages, he eventually declared bankruptcy in 2001 and was stripped of the parliamentary seat he held at the time.

Under Mr. Lee, Singapore instituted some of the world’s strictest gun-control and drug laws, enforcing them with mandatory death penalties. For example, automatic sentences of hanging were prescribed for trafficking slightly more than an ounce of cocaine, or for firing a gun while committing another crime, regardless of whether anyone was hit. As a result, Singapore has practically no gun crime and negligible drug problems. But it also regularly ranks among the top countries in executions per capita.

Mr. Lee was also a strong proponent of corporal punishment, notably caning. Singapore’s zeal for the penalty led to a diplomatic tiff with the United States in 1994 when an American teenager, Michael Fay, was sentenced to be caned for vandalism. U.S. officials saw the case largely as a Singaporean repudiation of American permissiveness.

A tendency to dabble in social engineering sometimes put Mr. Lee at odds with foreign critics, as well as Singaporean women. In the 1980s, his government set up the world’s only state-run matchmaking agency, in part to find mates for Singapore’s growing number of unmarried, ­college-educated women. Another program provided incentives for graduate mothers to have several children, reversing an overly successful family-planning campaign.

“If you don’t include your women graduates in your breeding pool . . . you would end up a more stupid society,” Mr. Lee complained in a 1983 speech.

In 1994, Mr. Lee even lamented that his government had been “young, ignorant and idealistic” when it had promoted equal education and employment rights for women decades earlier. As a consequence, he said, they were having a hard time finding husbands, because “the Asian male does not like to have a wife who is seen to be his equal at work.”

Some of his most controversial comments concerned democracy and its applicability to Asian societies.

“With few exceptions, democracy has not brought good government to new developing countries,” Mr. Lee said in a 1992 speech in Tokyo. “What Asians value may not necessarily be what Americans or Europeans value.” He ignited a furor in Manila the same year when, ignoring two decades of previous authoritarian rule, he told Philippine businessmen that their country needed “discipline more than democracy” to develop. “The exuberance of democracy leads to undisciplined and disorderly conditions which are inimical to development,” he said.

His outlook was perhaps best summed up in his 1997 biography. “Between being loved and being feared, I have always believed Machiavelli was right,” he told his biographer. “If nobody is afraid of me, I’m meaningless.”