New Jersey Gov. Thomas H. Kean, a mild-natured, moderate Republican, won reelection yesterday by a record margin -- carrying nearly every element of the electorate, including blacks, and sweeping his party into commanding control of the state Assembly.

Kean, elected in 1981 by the narrowest margin in state history, had 70 percent of the vote to 30 percent for Essex County Executive Peter Shapiro, with 95 percent of the state's 5,763 precincts reporting.

The same general support for incumbents that helped boost Kean to victory buoyed the reelection bids of several big city mayors. Edward I. Koch (D) of New York, George V. Voinovich (R) in overwhelmingly Democratic Cleveland, Coleman A. Young (D) of Detroit and Richard S. Caliguiri (D) of Pittsburgh easily won new terms.

In Houston, Mayor Kathy Whitmire (D) beat back a challenge from former mayor Louie Welch (R) to win a second term as the city's first woman mayor.

In Miami, however, massive computer snafus and 1,500 uncounted absentee ballots left the outcome uncertain, with Mayor Maurice A. Ferre (D) and two challengers separated by fewer than 1,500 votes.

When counting stopped early this morning, lawyer Xavier Suarez (Ind) had 16,012 votes, banker Raul Masvidal (Ind) had 15,412 and Ferre 14,613. The incumbent, seeking an unprecedented seventh two-year term, said he would demand a recount and ask for a federal investigation.

In New Jersey, Kean claimed victory, invoking the election of Abraham Lincoln as president in 1860 and saying he sought to unify the state in the same way Lincoln had brought together the nation.

"New Jersey is united tonight as it's never been united before," Kean said. "What I want to ask all of us to do is to use our new-found strength together the next four years. I ask you to help me make New Jersey all it should be and all it can be for the next four years."

Shapiro, facing a career-threatening loss, conceded defeat about an hour before Kean's victory speech. "Before tonight I ran in nine races and my record was 9 to 0," he said. "I ran in No. 10 tonight and I lost, and when I lose, it's really a doozy."

The GOP's New Jersey victory was in sharp contrast to a landmark Democratic sweep in Virginia. Former attorney general Gerald L. Baliles won the race for governor, state Sen. L. Douglas Wilder became the first black elected lieutenant governor and state Del. Mary Sue Terry was elected as Virginia's first female attorney general.

Strategists of both national parties looked to yesterday's results for evidence of realignment behind the GOP banner or resurgence of the Democrats, but most of the key contests appeared to have been fought on local issues and personalities.

In the Houston race, leadership and economic development in the once booming oil-and-gas city were key issues. In the last two weeks of the campaign, however, they were overshadowed by the concerns of a highly vocal group of antihomosexual activists seeking to capitalize on the growing public anxiety over acquired immune deficiency syndrome (AIDS), a fatal disease that has primarily afflicted homosexual men.

In January, Whitmire had supported a gay rights referendum that was overwhelmingly defeated.

The gay issue heated up in the final two weeks of the contest after Welch, in an off-the-cuff remark over an open television microphone, suggested that one way to control AIDS was to "shoot the queers." The next day, merchants in the heavily gay Montrose area began selling T-shirts that read, "Louie, Don't Shoot." They were countered with others emblazoned, "That a Boy, Louie. Make My Day."

Yesterday, one voter reported seeing shirts with an unstruck target on them and the salutation, "Louie, You Missed," in anticipation of a Welch loss.

Miami's Cuban community is composed almost entirely of persons who left the island after the Castro revolution. For years, they have coveted the mayor's office as a public position almost equal to a presidency of Cuba in exile, and early indications from yesterday's votes suggested that the Nov. 12 runoff may offer the best chance for that.

In Charlotte, Mayor Harvey B. Gantt (D) won a second term as the city's first black chief executive. Mayor Donald M. Fraser (D) was reelected in Minneapolis and George Latimer (D) won another term as mayor of St. Paul. Charles Royer (D) won his third term as mayor of Seattle. In Salt Lake City, appointed Mayor Palmer DePaulis (D) won a full two-year term.

Cleveland held school board elections in the shadow of the Jan. 26 suicide of Superintendent Frederick D. Holliday, who had blamed "petty politics" for making his job "meaningless."

Three well-financed, seasoned politicians -- businessman James M. Carney Jr., incumbent and former finance director Joesph G. Tegreene and former state legislator Benny Bonnano -- won seats on the board, along with incumbent Stanley Tolliver, a civil rights lawyer.

Board member Edward S. Young, considered Holliday's harshest critic, failed to win an additional term.

In Philadelphia, Republican Ronald D. Castille was elected district attorney, making him the first Republican to hold that city office in 12 years.

In the New Jersey gubernatorial contest, preelection polls showed Kean, 50, the son of a former congressman and a member of one of the state's first families, winning strong support among blacks, union members, Hispanics and city-dwellers.

He capitalized on the state's vastly improving economy, a skillful dominance of local and out-of-state media and a moderate record that eshewed confrontations over divisive social issues that are a staple of the conservative agenda.

Sensing a chance to seize power in the state Assembly, the GOP spent $1.2 million to boost Republican chances in 12 of the 80 Assembly seats up for grabs yesterday.

That effort paid off solidly yesterday as the Republicans switched 14 seats in the Assembly and assumed a 50-to-30 majority.