Prime Minister Margaret Thatcher's Conservative Party suffered a stunning defeat in a parliamentary by-election yesterday in a rural Welsh constituency, running a distant third behind the winning Liberal Party and the opposition Labor Party.

Liberal and Labor spokesmen proclaimed the vote, for what once was considered one of the Tories' "safest seats," an indication that the public overwhelmingly has begun to turn against Thatcher's tough economic policies and the prospect of ongoing high unemployment under her leadership.

"I believe it is the end of the prime minister's mandate, the end of Thatcherism," said Liberal Party victor Richard Livsey, whose victory marked the continued rise of the third-party alliance of Liberals and Social Democrats.

Liberal Party leader David Steel said the results, announced today, were part of a consistent move in the direction of the alliance during the past two years. Last May, the coalition, which pools its strength by not running in the same districts, won surprising gains in local county elections that indicated that British politics may be moving toward a true three-party system.

The Brecon and Radnor constituency, although the second-largest in Britain, holds only 48,000 voters. Predominantly rural, it has a long tradition of political independence and high voter interest that makes it a questionable indicator of the way Britain's overwhelmingly urban electorate might turn in the next general election in 1987.

But yesterday's vote was the first parliamentary race in six months and follows a period in which the Conservatives have dropped steadily in the polls and seen many economic indicators -- including unemployment, interest rates and inflation -- turn against them.

The Welsh seat last was contested during the 1983 general election, when the Conservatives won 48 percent of the vote, far outpacing Labor and the alliance, which polled 25 and 24 percent respectively. In yesterday's vote, held following the death of the Conservative elected two years ago, the Tories won only 28 percent, compared with 36 percent for the Liberals and 34 percent for Labor.

Conservative Party chairman John Selwyn Gummer discounted suggestions that the message was anti-Thatcher, saying that "it's always true in by-elections that the government party doesn't do very well." But, Gummer noted, "Of course, I'm disappointed."

The results came as a surprise, as none of the country's seven major polls had predicted an alliance win. Thatcher made no public comment on the election.

Despite the closeness of the top two contenders, with the Liberal and Labor candidates separated by only 559 of the nearly 40,000 votes cast, the outcome also was seen as a significant setback for Labor. Its strategists had hoped that the results would mark the first step in a comeback following the party's disastrous defeat in the 1983 general elections and would put the spotlight on party leader Neil Kinnock as a viable future prime minister.

Commentators and some party officials attributed Labor's second-place showing to "the Scargill factor," a reference to mineworkers' union head Arthur Scargill. Publicly associated with the violence and intransigence of the yearlong coal miners' strike that ended in March, Scargill returned to prominence in this week's union convention, calling on the next Labor government to release from jail and reinstate miners penalized during the strike.