LODZ, Poland (AP) _ A Solidarity candidate was elected mayor in Poland's second-largest city Monday, the first time the independent movement has taken control of a municipal government away from the Communist Party.

Waldemar Bohdanowicz defeated four other non-Communist candidates in a secret ballot by the municipal People's Council, ending a five-month impasse.

With Prime Minister Tadeusz Mazowiecki, a Solidarity journalist, leading the first non-communist government in the East bloc and the Communist Party's influence waning in factories, provincial and municipal governments have remained the last bastion of communist control.

But that too will be challenged next year when fully democratic elections for local councils are planned. Partially free voting in June parliamentary elections led to defeat for Communist candidates and overwhelming victories for those backed by Solidarity.

Lodz, a textile manufacturing city of 850,000 people about 80 miles southwest of Warsaw, has been without a mayor since May 29, when the previous Communist city president was ousted in a no-confidence vote following complaints of poor management.

An Oct. 11 bid to elect a replacement failed when the Communist-dominated council refused to elect either of the two Solidarity-aligned candidates put forth by Mazowiecki. The prime minister earlier had declined to nominate either of two candidates proposed by the communists.

But after an Oct. 23 meeting among representatives of the communists, Solidarity and other political groups, it was decided to entrust the choice to Mazowiecki, who approved five nominees, none from the party.

Bohdanowicz, one of the two rejected Oct. 11, got through Monday, receiving 110 out of 168 valid votes, according to the PAP news agency.

The prime minister must approve candidates for mayors before they can be elected by the municipal councils.

The Mazowiecki government, which assumed power in August, is preparing to reform the system, allowing communities to select their own representatives without interference from Warsaw.

Bohdanowicz, 48, has been a Solidarity activist since the independent movement was founded in 1980.

He said he is ''proposing cooperation to everyone who desires the good of Lodz.''