WARSAW, OCT. 4 -- Prime Minister Tadeusz Mazowiecki agreed today to run for president of Poland against his former ally, Solidarity union chairman Lech Walesa.

The announcement kicks off the first popularly contested race for president in Polish history. It will be a head-to-head confrontation between the country's two best-known politicians.

When Mazowiecki became the first non-Communist head of government in the East Bloc in the summer of 1989, he was handpicked for the job by Walesa.

Since then, Walesa has accused Mazowiecki's government of being too slow to privatize the state-owned economy and to dismiss former Communists from positions of authority in government and industry. Mazowiecki supporters accuse Walesa of demagoguery and of tapping into ultra-nationalist and antisemitic sentiments in the Polish working class.

After several weeks of hesitation, Mazowiecki made his announcement on national television. "The time for an answer has come, and today I want to give this answer, a short one," Mazowiecki said.

"Following great deliberations and consideration of all circumstances, I have decided to express approval if my candidacy is put forward," he said. "One must move forward. One cannot retreat from the path Poland has chosen and fought for so hard this year."

The race for the presidency is likely to sharpen an emerging conflict between the urban and professional elite, which strongly supports Mazowiecki, and the working class, which backs Walesa. Until Walesa began criticizing the government, the unique strength of the Solidarity movement had been its capacity to embrace the interests of both workers and professionals.

Besides lambasting Mazowiecki for moving too slowly in implementing change, Walesa has made populist promises to workers about how the human cost of free-market reform -- increased unemployment and reduced social benefits -- need not be high. Mazowiecki supporters accuse Walesa of making unrealistic promises and undercutting popular support for long-overdue economic reform.

The elections are scheduled Nov. 25. Aside from Walesa and Mazowiecki, several minor candidates are also expected to seek a place on the ballot.

Walesa announced his campaign for president Sept. 16 and held his first meeting with potential voters Monday in the central city of Torun.

The office will be vacant because Gen. Wojciech Jaruzelski, the former Communist leader, asked parliament last month to have his six-year term shortened after 17 months as president, citing public demands for a popularly elected leader.

The Senate passed the final legislation setting up the elections Saturday, and Jaruzelski signed it into law Monday.

Mazowiecki, 63, a longtime journalist and a former political prisoner, became prime minister Aug. 24, 1989. His nomination came after Communists failed to win sufficient support to govern in quasi-democratic elections two months earlier.

In his year in office, Mazowiecki has won broad public support for a "shock therapy" economic package that has ended hyperinflation and filled long-empty shops with goods.

The prime minister has consistently led Walesa in public opinion polls in the past nine months, although in recent weeks Walesa has been gaining. Walesa, relying on regional branches of Solidarity and on workers in large industries, is considered to have a much stronger grass-roots organization than Mazowiecki.