The bitter Massachusetts Democratic gubernatorial primary winds up this weekend with polls indicating that Gov. Edward J. King may have fought off the challenge of ex-governor Michael S. Dukakis.

At least two private polls taken within the last week showed that the race is a tossup, and the widest margin reported for Dukakis -- in a third poll -- was less than 10 points. That is a far cry from the 30-point edge Dukakis enjoyed last spring, when he won endorsement over the governor from the state Democratic convention.

Dukakis' efforts to link King to charges of corruption in the state administration and to the economic policies of President Reagan have continued unabated. But King has apparently profited from his counterpunches aimed, not only at Dukakis, but at the liberal traditions of the state party's leader, Sen. Edward M. Kennedy (D-Mass.).

There aren't many Massachusetts Democrats who go out of their way to repudiate Kennedy, but King is not your ordinary Democrat. He backed President Carter over Kennedy in 1980, and when Kennedy endorsed Dukakis in Tuesday's primary, King did not duck or play down the issue.

"Kennedy said he is much more philosophically aligned with Dukakis," King said in an interview soon after the endorsement, "and I agree with that. We are clearly at opposite ends of the party."

It is King's willingness to dramatize the split in the party, as much as the bitter charges of corruption, that has made this primary more of a civil war than a political campaign.

Dukakis, who was blind-sided by King in a parallel fight four years ago, when he was the incumbent, has been sitting on a dwindling lead and trying to retain an aura of statesmanship, despite a television campaign devoted largely to implications that King has presided over "a recognizable pattern" of official chicanery.

"There are not two Democratic parties here, despite King's efforts to make it seem that way," Dukakis said. "There is one Democratic Party -- the party that Ted Kennedy and I both believe in, and it's a party of working men and women, of the elderly and the young, and it is concerned with all their problems."

Dukakis points to his support from many of the industrial unions and such blue-collar Democrats as Rep. Joseph D. Early of Worcester to refute King's charge that it was the "elitists" who gave Dukakis the endorsement at last spring's state convention and who fuel his campaign effort.

But a study of those delegates by two political scientists showed sharp polarization on many questions, including self-identification as liberals or conservatives. And a Boston Globe poll of likely primary voters also showed some significant splits. The poll, completed Aug. 24, gave Dukakis a 53-to-31 percent lead overall.

The size of the overall Dukakis lead was discounted by almost everyone, including the former governor's own managers, who believe there is a "hidden" King vote, among the professedly undecided, as there was when King upset Dukakis four years ago.

As in 1978, King has been the aggressor through much of the campaign, saying a Dukakis victory would return the state to policies of rising taxes and rising welfare rolls, which he claims -- over Dukakis' protests -- to have reversed. "What was so good about the good old days of Mike Dukakis?" King's TV ads ask.

In response, Dukakis has rolled out TV spots charging that King's publicized tax cuts have boosted user fees for many services and have come only at the price of the worst tax of all -- "the corruption tax."

The corruption charges have been fueled by an ongoing investigation of the state revenue department, which has seen the suicide this summer of a deputy commissioner who was a boyhood friend of the governor's and the forced resignation of another official with a criminal record who was apparently recommended for appointment by the governor.

But King has laid down his own line of attack, emphasizing his contrast to Dukakis on a series of social issues. Over and over, King hammers the differences: He is for the death penalty and mandatory minimum sentences and a higher driving age and tougher drunk-driving penalties and against taxpayer-financed abortions. On all of them, he says, Dukakis has taken opposing stands.

The hammering on corruption and the social issues has obscured what both men first seemed to agree was a basic debate on economic policy. King trumpeted his admiration for President Reagan's tax and budget reductions, while Dukakis promised that he would never allow himself to be called "Reagan's favorite Democratic governor."

But both men have trimmed their sails. King conceded in a recent interview that after two years of Reaganomics, "I can't say the economic picture is good." Now he is emphasizing his own support of some traditional Democratic programs -- including assistance to the elderly -- and publicizing an endorsement from Rep. Claude Pepper (D-Fla.), the national spokesman for Democrats on Social Security.

For his part, Dukakis plays down the potential cost of his own programs, like expanding police and prosecutorial staffs to curb crime, for fear of feeding the King theme that Dukakis' nomination would again saddle the commonwealth with the label of "Taxachusetts."

The din of their battle, particularly on the airwaves, has relegated the three-way Republican primary to second place. But there are fears among some Democrats -- confirmed, in part, by The Globe poll -- that the Democratic split might be so serious as to open the way for the minority Republicans to recapture the governorship for the first time in eight years.

For the moment, however, neither King nor Dukakis is saving ammunition, money -- or venom -- for November.