Tadeusz Mazowiecki, who in 1989 became Eastern Europe’s first democratically elected prime minister after communism, was a key adviser to Poland’s Solidarity freedom movement and U.N. human rights envoy to Bosnia in the 1990s, died Oct. 28 in Warsaw. He was 86.

His personal secretary, Michal Prochwicz, told the Associated Press that the former prime minister was taken to the hospital Wednesday with a high fever.

As prime minister, Mr. Mazowiecki called for drawing a “thick line” to separate the communist past from new Poland, a much-criticized position that contributed to his ouster after a year in office.

In August 1980, Mr. Mazowiecki joined thousands of workers on strike at the Gdansk Shipyard to demand restitution of a job for fired colleague Anna Walentynowicz, better pay and a monument to workers killed in the 1970 protest. Within days, their action grew into a massive wave of strikes that gave birth to Solidarity, Eastern Europe’s first free trade union and a nationwide freedom movement. It was led by a charismatic shipyard electrician, Lech Walesa, whose name quickly became known around the globe.

From the days of the strike until well into Poland’s democracy in the 1990s, Mr. Mazowiecki was among Walesa’s closest counselors. He advised Walesa in the tough yet successful negotiations with the communists, who granted union and civic freedoms in 1980.

Former Polish Prime Minister Tadeusz Mazowiecki gesturing the “V” sign after a confidence vote on his government in Warsaw, Poland, Sept. 12, 1989. Mazowiecki died Oct. 28, 2013, at the age of 86. (GRZEOGORZ ROGINSKI/EPA)

Like Walesa and many Solidarity activists, Mr. Mazowiecki was detained for months under the martial law that Poland’s last communist leader, Gen. Wojciech Jaruzelski, imposed on Dec.13, 1981, to curb the freedom that had irritated Moscow.

After one year in confinement, Mr. Mazowiecki returned to Walesa’s side and wrote reports about the stagnation of social and economic life under martial law.

The hardships inspired a new wave of strikes in 1988. Mazowiecki walked arm in arm with Walesa at the head of angry workers in Gdansk. The renewed protests brought the communists to the negotiating table with Solidarity to discuss the terms of democratization. Mr. Mazowiecki wrote many of these terms.

In September 1989, Mr. Mazowiecki became the former communist bloc’s first democratic prime minister.

He helped initiate a series of economic reforms to curb inflation, but the effect was high unemployment from closed industries and state-run farms.

The price of the reforms was high. Mr. Mazowiecki unexpectedly lost in the first free presidential election in 1990 to a complete unknown, a Polish emigre from Peru, Stan Tyminski. Walesa won in the runoff.

In 1992, Mr. Mazowiecki was appointed the first U.N. envoy to war-torn Bosnia and widely reported on atrocities there. Angered by a lack of international reaction to the killings, which he termed as war crimes, he resigned in 1995.

Mr. Mazowiecki continued as a lawmaker and politician in Poland and co-wrote the 1997 Constitution.

He was born April 18, 1927, in the central city of Plock to the deeply religious family of a medical doctor. Under the Nazi German occupation of Poland during World War II, the teenage Mr. Mazowiecki worked as a messenger.

After the war, he studied law at Warsaw University but did not obtain a degree, engaging instead in journalism and politics.

He was twice widowed. Survivors include three sons from his second marriage.

— Associated Press