The Massachusetts Democratic convention today rejected, by 2 to 1, the reelection bid of conservative Gov. Edward J. King, giving its endorsement instead to Michael S. Dukakis, the liberal that King ousted from the governorship four years ago.

The 2,212-to-1,052 vote in favor of Dukakis set the stage for a bitter rematch of the two rivals in the Democratic primary on Sept. 14.

King, whose economic and social policies have made him an ally and defender of President Reagan, dismissed Dukakis' victory here as the product of a "very tight, narrow group of self-proclaimed representatives of the Democratic Party," and said he would reverse the outcome with the help of "mainstream voters" in the primary.

But Dukakis, whose career seemed at an end when King upset him in the 1978 gubernatorial primary, promised his supporters victory and said, "I can promise you that if we win this election, Mike Dukakis won't be Ronald Reagan's favorite governor."

Three different polls taken last month showed Dukakis with leads of 18 to 32 points over King among likely primary voters. But King apparently has halted his long decline in popularity and has raised at least $600,000 for a media campaign against his challenger.

The governor said today that he would emphasize his record of support of tax cuts, welfare reductions, the death penalty and mandatory sentencing and his opposition to state-financed abortion, the same issues he used to upset Dukakis four years ago.

Dukakis, in turn, hammered on the issue of corruption, promising an administration where "cabinet secretaries can't be bought and contracts can't be wired." One of King's top appointees has been jailed on bribery charges.

The endorsing convention in the Springfield Civic Center was the first Massachusetts Democrats have held in 12 years. In 1970, when they last tried such a procedure, the endorsed candidate, state Senate President Maurice A. Donahue, was defeated in the primary by Boston Mayor Kevin H. White, who, in turn, lost to Republican Francis W. Sargent.

Republicans are hoping that the same pattern of intraparty Democratic bitterness will open the way for their victory in November.

Three Republicans--former Boston city councilman John W. Sears, state Rep. Andrew Card and businessman John R. Lakian, are contending for the GOP nomination, with Lakian carrying the endorsement of his party's convention.

But some Democratic officials talked of the weekend proceedings here as the harbinger of a party revival. King's victory in the 1978 election was followed by an even greater upset, when Democratic defections to independent John B. Anderson enabled Reagan to carry Massachusetts in 1980. Last year, the state Democratic Party adopted a new charter, calling for mass meetings to select delegates to platform and endorsing conventions.

Dukakis said today that the 108,000 Democrats who turned out for the caucuses last February represented "the backbone of the party," but, as in the last Democratic National Convention, teachers and other government employes were represented well beyond their share of the population.

King's forces and many other old-line elected officials tended to ignore the convention until the state Supreme Court last month--in a surprise verdict--upheld as binding a new state party rule that said the primary ballot would be open only to candidates who received at least 15 percent of the convention endorsement vote.

At that point, King mobilized his forces and enlisted a number of other officials with loyalties or obligations to him, to assure he would not be barred from the primary. His vote here, while embarrassing for an incumbent, was somewhat higher than pre-convention forecasts, indicating the effectiveness of some of his last-minute efforts.

The King-Dukakis fight and an eight-way battle among lieutenant governor hopefuls overshadowed the endorsement by acclamation of Sen. Edward M. Kennedy (D-Mass.).

Kennedy, who is heavily favored for reelection over Republican challenger Ray Shamie, delivered an assault on Reagan's economic policies, telling the delegates that "the Reagan cheese lines of 1982 are as unacceptable as the Hoover bread lines of 1932."

"I take some satisfaction," he said, "in the fact that I am the only senator running for reelection in 1982 who voted against the incredible Reagan policy of tax cuts for the privileged and budget cuts for the poor and middle class."

The convention also marked at least a temporary politic farewell for Lt. Gov. Thomas P. O'Neill III (D), son of the speaker of the U.S. House of Representatives. He bowed out of the governor's race a few weeks ago and left Springfield for a vacation in Ireland.

Young O'Neill is rumored to be interested in the Boston mayoralty when it comes up next year.