Instead of retreating, Mr. Soares continued his crusade against the dictatorship and its colonial wars, and within a year he was sent into exile again, this time in Europe.

In France, he secured part-time teaching jobs at the Sorbonne and the University of Rennes. He kept a modest apartment on the Left Bank in Paris, where he wrote about his struggles against fascism and bolstered the opposition among immigrants and other exiles. He also consolidated his ties with other Socialist leaders and announced the creation of the Portuguese Socialist Party during a conference in West Germany in 1973.

By the time the dictatorship fell in the bloodless Carnation Revolution of 1974, Mr. Soares had been jailed 12 times — serving a total of three years — and had lived in exile for almost five years. (A former inmate was quoted as saying that even in prison the ebullient Mr. Soares “was always in a splendid mood and made us laugh.”) When he arrived by train in Lisbon from Paris after the revolt, he was mobbed by thousands of supporters.

He first served as foreign minister under the military-controlled civilian government and led the decolonization in Africa, ending years of war in Guinea-Bissau, Angola, Mozambique and other territories. But the government grew more radical under the influence of the Moscow-aligned Communist Party, prompting Mr. Soares to pull his party out of the coalition in 1975.

He organized street rallies and, with the help of a moderate military faction, ousted the pro-Communist prime minister, Vasco Gonçalves. Elections were called in 1976, and Mr. Soares won, making him the first constitutionally elected prime minister after the revolution.

“What we believe in,” he said after his victory, “is a socialism in liberty, neither dictatorship of the left nor dictatorship of the right.”

He served during a politically tumultuous period that saw coalitions form and dissolve. He was the head of two governments until 1979, and then of a third from 1983 to 1985.