Prime Minister Margaret Thatcher announced her resignation Thursday after 11 1/2 years in Britain's highest office, felled amid waning popularity in a leadership challenge from a Conservative Party rival.

Thatcher had failed on Tuesday to decisively fend off Michael Heseltine, who quit as her defense minister in 1986, in a vote by Conservatives in Parliament that constituted the first serious challenge to her leadership.That forced a second ballot, to be held next week, and Thatcher's office said her resignation will take effect as soon the governing party lawmakers elect a new leader.

"I have concluded the unity of the party and prospects of victory in a general election would be better served if I stood down to enable Cabinet colleagues to enter the ballot for the leadership," she said in a statement.

Likely challengers to Heseltine include Foreign Secretary Douglas Hurd and treasury chief John Major, both of whom have been talked up by some of their colleagues in the House of Commons.

The announcement that Thatcher would resign came barely 21/2 hours before the deadline for other candidates to enter the Conservative leadership race. In Tuesday's second round, only a simple majority will be needed to win.

Heseltine won enough votes in the first round of balloting among the 372 Conservative members of Commons to deny Thatcher an outright victory.

Many observers saw that failure as tantamount to defeat.

Thatcher is Europe's longest-serving government leader, but the Conservatives have dropped behind the opposition Labor Party in the polls.

The governing party has been hurt by rising inflation, high interest rates and its imposition of a new per capita local services tax that is extremely unpopular because it taxes each adult the same amount.

Labor leader Neil Kinnock hailed the news of his nemesis's departure.

"Good. Very good indeed. I cannot pretend otherwise," Kinnock said.

Whoever becomes prime minister must call new parliamentary elections by mid-1992.

Shares on the London Stock Exchange shot higher following the news Thatcher was withdrawing. "The market is going mad in relief," said Peter Furlong, senior U.K. equities dealer at Daiwa Securities.

The Financial Times-Stock Exchange 100 Share index soared 33 points immediately on hearing the news of the prime minister's resignation.

A statement issued by Thatcher's office said:

"The prime minister has informed the queen that she doesn't intend to contest the second ballot in the election of a leader of the Conservative Party and intends to resign as prime minister as soon as a new leader of the party has been elected. The prime minister will seek an audience with the queen later this morning to convey her decision to her majesty."