A hard-fought contest in Western Maryland highlighted congressional primary races otherwise expected to produce no upsets or surprises throughout the state yesterday.

In the 61th District, stretching from Howard and Baltimore counties to Garrett County at the westernmost end of the state, attorney Dan Rupli presented a strong challenge to Democratic incumbent Goodloe E. Bryon. Rupli was making a second attempt to unseat Byron, who had raised more than $100,000 in what was billed in part as an ideological battle.

Three Republican incumbents - the Eastern Shore's Robert E. Bauman, Anne Arundel County's Marjorie S. Holt and Montgomery's Newton I. Steers Jr. - faced no primary opposition.

Incumbent Democrats Barbara Mikulski and Parren Mitchell in Baltimore, Clarence Long in Baltimore County and Gladys N. Spellman in Prince George's were expected to overcome primary opponents early.

In Montgomery County, Democrat Michael D. Barnes was so confident of victory that he began aiming at Steers even before yesterday's vote. In Holt's district, Democrat Sue Ward, also expecting victory, said she was preparing for an "extremely difficult" uphill campaign for the general election.

Three Democrats, competed in the 4th District to oppose Holt in November. The district stretches from Baltimore City to Washington, but two-thirds of its voters live in Anne Arundel, where Mrs. Holt formerly was clerk of the county court.

Holt has represented the district since its creation in 1972, despite a 3-to-1 Democratic edge in registration.

In the Fifth District, solely in Prince George's County where federal workers make up a large share of the voters, incumbent Democrat Spellman ran for a third term. She won the seat in 1974 after eight years of Republican occupancy.

Spellman, 60, rose to power in Prince George's County politics as a reformer and now serves her consituents on the House Post Office and Civil Service Committee. Her challenger, Davis J. Tomasin, was a 25-year-old University of Maryland graduate who once worked for County Executive Winfield M. Kelly. Three Republicans campaigned for the chance to run for Spellman's congressional seat in the general election.

Rupli, a Burkittsville lawyer and self-described product of the working class, waged a spirited campaign, his second, against Democrat Byron in the large 6th District. The district includes the self-consciously liberal new town of Columbia and the industrial city of Cumberland.

Bryon, whose father once represented the same district in Congress, was elected in 1970. Since the last campaign, in which Rupli made a strong showing, Byron shifted from rock-ribbed conservation to the middle of the road.

As he did in 1976, Rupli attacked Byron as a foe of environmentalists, citing Byron's campaign contributions from big utilities this year. Byron scoffed at Rupli's Harry Truman-style campaign complete with a "campaign special" pickup truck modeled after Truman's 1948 whistle-stopping railroad train.

In Montgomery County's 8th District, five Democrats were on the ballot, but Barnes received such widespread support he began gearing up before yesterday's primary to oppose Steers in November. Barnes, 35, virtually ignored his Democratic competitors while attacking Steers as "an ineffective legislator."