BELFAST, Northern Ireland (AP) _ Prime Minister Margaret Thatcher, heavily guarded during a surprise visit to Northern Ireland, said Wednesday that Britain is more determined than ever to defeat terrorism.

''I feel strongly that terrorism must never, never win,'' she told a group of police officers and widows of murdered members of the force in east Belfast. ''If it did that would spell the end of democracy.''

Mrs. Thatcher stayed away from Roman Catholic strongholds, but Protestant demonstrators in Lisburn yelled ''Traitor, Traitor, Traitor'' and ''Go Back To England'' as she made her way through the streets where six soldiers were blown up by an Irish Republican Army bomb in June.

The demonstrators oppose the 1985 Anglo-Irish agreement giving the Irish Republic a voice in Northern Ireland's administrative affairs. Some Protestants see the accord as a betrayal by the British and the first step toward a Catholic-dominated united Ireland.

Mrs. Thatcher, who escaped an IRA assassination attempt at a 1984 conference of her governing Conservative Party, told the police officers she heard people suggest that more IRA attacks would make the public weary.

''You don't know the spirit of Northern Ireland or the spirit of the United Kingdom,'' she said. ''The more difficult things are, the greater our resolve, determination and courage to defeat that terrorism which is a cancer in our midst.''

The IRA is fighting to oust Britain from Protestant-dominated Northern Ireland and unite the province with the Roman Catholic Irish Republic under a socialist government.

This year, it has stepped up its attacks on British soldiers, killing 27 in Northern Ireland, mainland Britain and continental Europe. Leaders of Sinn Fein, the IRA's legal political wing, have said one aim of targeting the soldiers is to create public opposition to a continued British presence in the province.

Security forces mounted a huge security operation for Mrs. Thatcher's visit, her second to Northern Ireland in less than a year. Last November, she attended a memorial service in Enniskillen for 11 people killed when the IRA bombed a ceremony for Britain's war dead.

No advance information on her itinerary was released for security reasons.

Sinn Fein publicity director Danny Morrison said the secrecy and intense security ''shows how vulnerable she feels and just how tenuous is British rule here.''

Mrs. Thatcher told the police officers that she was grateful for the sacrifices of their colleagues and their continued efforts to maintain freedom and democracy. Among the audience was policewoman Alison Johnston, 26, who lost an eye in an IRA bombing in County Fermanagh on Aug. 18.

''When we have got rid of terrorism, and we must get rid of terrorism, this is a marvelous country, a country which can be very prosperous, if again you can get the security that the rest of us in the United Kingdom take for granted,'' she said.

Mrs. Thatcher also visited several thriving factories and businesses during her day-long tour. John Hume, leader of the moderate Catholic Social Democratic and Labor Party, said he hoped her visit would help create new jobs.