Harry Roe Hughes, a political loner who came out of nowhere to seize the Democratic gubernatorial nomination, was elected Maryland's 57th governor last night, easily defeating Republican J. Glenn Beall Jr.

Hughes led what is believed to be a Democratic sweep of statewide offices. Stephen H. Sachs, who pioneered the federal prosecution of political corruption in Maryland, led Republican Warren G. Rich by a comfortable margin in the race for attorney general, and Comptroller Louis L. Goldstein easily beat Republican Donald Devine to win his sixth term.

In the race for Prince George's County executive, incumbent Democrat Winfield M. Kelly Jr. was trailing former congressman Lawrence J. Hogan in early returns.

Charles W. Gilchrist, attempting to become the first Democrat county executive in Montgomery County history was leading Richmond M. (Max) Keeney. Voters in that county were almost evenly divided in early balloting on the controversial charter amendment to cut county property taxes.

A similar tax-cutting amendment in Prince George's County was faring better in scattered early returns.

In Maryland Congressional races, incumbents Gladys Noon Spellman, a two-term Democrat from Prince George's County, and Marjorie S. Holt, a three-term Republican who represents Anne Arundel and the southern tip of Prince George's, won re-election easily.

Beverly B. Bryon also won overwhelming and will represent western Maryland in Congress, filling the seat vacated when her husband, Rep. Newton I. Steers was trailing slightly behind Michael D. Barnes in early results. Barnes is the first Democrat to seriously challenge the liberal Republican stronghold on the Congressional seat for Montgomery County.

Hughes, 51, the former state transportation chief who resigned in protest last year after suspecting wrong-doing in the award of a subway contract, entered the general election as a strong favorite over Beall, 51, who was attempting to make a comeback after losing his U.S. Senate seat in 1976.

In the seven weeks of the campaign both candidates promised to slash taxes by at least $80 million, bring new industry into the state, restore integrity to government, cut government bureaucracy and forbid public employes from striking or engaging in binding arbitration.

The candidates agreed on most of the issues, and the campaign, in the end, seemed anticlimatic in comparison to the excitement of the Democratic primary. Then Hughes defied every political convention by winning without big money, heavy advertising or a large volunteer organization and without the backing of regular Democrats and labor.

Several times during the primary, Hughes' rating in the polls was so low and his campaign coffers so drained that he considered dropping out of the race or dropping back to a lower spot on the ticket of another candidate.

Lee rejected him as a lieutenant governor running mate, choosing Senate president Steny H. Hoyer instead. Hughes' fortune began turning in late August when The Baltimore Sunpapers broke precedent and endorsed him four days in succession, once publishing their choice on the front page. At the same time, he began outperforming his three opponents on television debates.

Not only did Hughes unseat a sitting governor for the first time this century, he also trounced Baltimore County Executive Theodore G. Venetoulis in his own county and soundly defeated his fourth opponent, Baltimore City Council president Walter S. Orlinsky in his own home base of Baltimore.

Hughes' primary victory was more than a stunning upset. It was seen as a final repudiation of Gov. Marvin Mandel, who was suspended from office last year after his conviction on political corruption charges. Lee served as Mandel's lieutenant governor for seven years and took over the government after the conviction.

Hughes moved quickly after the primary to unite his party, assuring himself the status of the front-runner in the race because of the 3-to-1 edge in voter registration held by Democrats. Then, he essentially sat on his lead. He avoided controversy by making few promises, avoiding specific proposals and even withholding several position papers prepared for him.

His most specific campaign promise, a tax relief package he said would save taxpayers $86 million, was a rehash of old ideas and fell short of his controversial proposal in the primary to further graduate the state's income tax. He said he still likes the income tax approach, but decided against proposing it.

As the front runner, he collected endorsements from most special interest groups, including organized labor and teachers, without much effort and easily raised about $300,000 to pay for a moderately heavy television and radio advertising campaign.

Beall was the more aggressive campaigner, attacking Hughes' record as transportation secretary and accusing him of waffling on his tax proposal. The Republican candidate held press conferences every Monday where he issued position papers on topics ranging from taxes to the elderly.

Beall and Allen spent much of their time courting Maryland's sizable black vote, attempting to lure that traditionally Democratic bloc over to the Republican column. Beall also aimed his message of fiscal conservatism at normally Democratic blue collar workers.

Nevertheless, polls published as recently as two days ago in The Baltimore Sun showed Hughes with a sizable lead over Beall, and also showed that Beall had not made the major gains among Democratic voters for which he had hoped.

Even the normally quiet Republican party had a contentious primary. Beall easily won the nomination but had to defend himself against attacks by two of his three opponents who criticized him for his previous associations with former President Nixon.

Since the primary, much of the controversy and attention has centered on the two nominees for lieutenant governor.

Bohley, 36, a two-term councilman for Prince George's who was Hughes' last-minute choice for lieutenant governor, became preoccupied with the question of succession soon after the primary and asked groups to pray for Hughes' health because Bogley was not ready to serve as chief executive.

Then, on Sept. 29, Bohley created the biggest sensation of the campaign. After proclaiming his opposition to abortion, he said he might have to withdraw his candidacy unless he could resolve his differences on the issues with Hughes, who supports public funding of abortion for poor women. Bogley said he was not sure he could continue the policy if Hughes left office before his term expired and Bogley became acting governor.

Bogley's statement touched off a wild sequence of events at Hughes' campaign headquarters. He told reporters he was strongly influenced by his wife's ardent antiabortion views and brought her out to speak for herself. Rita Bogley criticized the state's abortion policy, illustrating her views with a packet full of pictures showing aborted fetuses.

Hughes spent more than five hours that night trying to resolve he differences with Bogley and keep the ticket together. The two men emerged from a marathon meeting in Hughes' inner office near midnight with a two-page statement. In it Bogley promised to pursue all of Hughes's programs if he should be forced to become acting governor before Hughes' term expired.

Allen, the Republican nominee for lieutenant governor, quickly seized the initiative by reminding voters that he agreed with his running mate on almost every important issue. He also stressed his own experience as a physician, GOP party chairman, community activist and former member of the House of Delegates to contrast with Bogley's relative inexperience.

Allen drew attention for another reason. As the first black candidate for statewide office and a Republican, he hoped to win support of large numbers of black voters who traditionally vote Democratic. He spent days campaigning in black communities of Baltimore and Prince George's trying to crack the Democratic hold.

Allen's candidacy created a real dilemma for black Democrats. Many said they liked Allen, but had difficulty supporting his conservative running mate, Beall, who consistently opposed busing you achieve racial integration of schools. Hughes did not court the black vote as assidously, but was considered to have a good voting record on civil rights.

Beall's advisers were concerned that Allen's attraction to black voters could be offset by a white backlash in conservative pockets of the state.