Maryland, a pocket of hope for the Democratic party, was swept up last night by the national Republican landslide as President Reagan narrowly defeated Walter F. Mondale with nearly all of the returns in.

With 99 percent of the state's 1,512 precincts reporting, Reagan was leading Mondale by a 52-to-48 margin and was ahead in all the state's jurisdictions except Baltimore and Prince George's counties. In a surprise in Montgomery County, Reagan won by only 400 votes, a much smaller margin than in 1980.

Reagan's overwhelming strength statewide assured his victory in one of six states President Carter carried in 1980.

"We've redeemed ourselves," said a jubilant Allan C. Levey, chairman of the Maryland GOP, at a victory party in Annapolis. "We've really showed them in Maryland."

At Democratic headquarters in Baltimore, the mood was somber. Rep. Barbara A. Mikulski, a Baltimore Democrat and national cochairman of the Mondale campaign, said she called the former vice president late yesterday afternoon and said, "Walter, I'm proud of you."

Reagan found his core of support in Baltimore County, an affluent bedrock of Republicanism, and among white ethnic voters in Baltimore who usually vote Democratic. These voters appeared to offset a large turnout among black voters who in the past had been able to guarantee a Democratic victory.

Vice President George Bush had campaigned in Baltimore County last Saturday, and GOP officials said his visit helped spur a large Republican turnout.

In Baltimore, Mondale had a plurality of slightly more than 100,000 votes, but his campaign strategists had said he would need to increase the 133,000-vote margin Carter had in the city in 1980 to carry the state.

In Prince George's, Mondale increased the Democratic margin over 1980, but not enough to propel a statewide victory.

One of the biggest surprises of the evening was the race in Montgomery, which Reagan carried in 1980 and was favored to win again this year.

For Democrats, a victory in Maryland had taken on symbolic proportions. With a 3-to-1 edge in voter registration and all of the state's top offices held by Democrats, Mondale and his supporters believed that a last minute blitz during the final days of the campaign would protect the state from a Republican landslide.

Mondale and his running mate, Geraldine A. Ferraro, both campaigned in Baltimore during the last week, hoping particularly to energize the potent black electorate in the city.

In 1980, President Carter won only four of the state's 24 jurisdictions -- Baltimore city, Prince George's, Kent and Somerset counties -- but carried the state by 46,000 votes, for a margin of 47 to 44 percent.

From the outset of the 1984 campaign, Mondale seemed to have bright prospects in Maryland, where registered Democrats outnumber Republicans 3 to 1. More than a year ago, Mondale was endorsed by all of Maryland's leading Democrats: U.S. Sen. Paul S. Sarbanes, Gov. Harry R. Hughes, Attorney General Stephen H. Sachs, Reps. Steny Hoyer and Michael D. Barnes, who represent the critical Washington suburbs and Reps. Barbara Mikulski and Parren J. Mitchell of Baltimore.

In addition, Mondale had strong backing from labor, one of the most potent and organized political forces in the state.

Yet obstacles arose during the course of the primary and general election campaigns. For Mondale, Jesse L. Jackson's strong showing in the May 8 primary turned out to be a double-edged sword.

On the one hand, thousands of new Democrats registered to vote in Prince George's and Baltimore city and seemed to give the party a strong advantage going into the general election. But these new voters did not offer automatic allegiance to the Democratic nominee.

For months, as Jackson bargained with the Mondale campaign to be more sensitive to black concerns, Maryland's newly aroused black electorate was reluctant to commit fully to the Democratic ticket.

As late as the final week of the campaign, some black ministers in Baltimore expressed anger that on his only recent visit to the state, Mondale would not go to the inner city and chose instead to have a rally at Baltimore's posh Inner Harbor.

Mondale also had problems with some of the state's Democrats, most notably Baltimore Mayor William Donald Schaefer, who only involved himself in the campaign only in the final weeks.

In Baltimore County, a Republican stronghold and an area of increasing influence on the outcomes of statewide races, Democratic County Executive Donald J. Hutchinson was a latecomer to the Mondale cause. commit fully to the Democratic ticket.

As late as the final week of the campaign, some black ministers in Baltimore expressed anger that on his only recent visit to the state, Mondale would not go to the inner city and chose instead to have a rally at Baltimore's posh Inner Harbor.

Mondale also had problems with some of the state's Democrats, most notably Baltimore Mayor William Donald Schaefer, who only involved himself in the campaign only in the final weeks.

In Baltimore County, a Republican stronghold and an area of increasing influence on the outcomes of statewide races, Democratic County Executive Donald J. Hutchinson was a latecomer to the Mondale cause.