At first, a group of Maryland legislators thought they had found a made-to-order election-year crusade. The idea was to abolish the state's hotly debated auto pollution inspection program, and then tell the folks back home how they saved them the trouble of a $9 car test and got the government off their backs.

But this week the crusade lost some of its fiscal-conservative punch. It turns out that in order to save each motorist $9, the state would have to pay up to $10 million to cancel a contract with a private firm that has already begun setting up inspection stations around the state.

Legislators upset about the price tag are turning their ire on Gov. Harry Hughes, who signed the contract with the California firm last year in the face of legislative threats to kill the program during this session. Hughes argued then and now that Maryland was forced to proceed with the program to meet federal clean air standards by 1987.

But the clean air issue has been lost for now in an election-year uproar that has transformed a dry, 40-page contract entitled "Vehicle Emissions Inspections Program Agreement" into the centerpiece of a juicy statehouse feud between the governor and some of his wiliest adversaries.

Hughes' critics contend that the state was far too lenient in promising to repay the contractor for expenses in case of a state pullout. As their main ammunition, opponents point out that the contractor, Systems Control Inc. of Palo Alto, Calif., is represented by a law firm with close ties to Hughes. Judson Garrett, Hughes' former legislative aide who lobbied for the emissions control law in 1979, represented Systems Control in the contract negotiations; and Michael McWilliams, Hughes' longtime friend and 1978 campaign manager, is a partner in the Baltimore firm of Tydings and Rosenberg where Garrett works.

No legislator claims to have evidence of favoritism, and many acknowledge that it is a truism that legal business flows to firms with political ties.

Hughes, in an interview, defended the contract, which was awarded through competitive bidding, and Garrett's role in negotiating it with state attorneys. "You always get a little concerned about appearances but I know Jud is an honorable man," Hughes said.

Hughes' supporters contend that most of the criticism is being orchestrated by Sen. Harry J. McGuirk (D-Baltimore), who has floated plans to run against the governor in November. The Senate leadership, prodded by McGuirk, has held two meetings to investigate the contract, and Hughes' legislative critics have spent hours combing through it, saying that "it doesn't look right" for a governor who was elected on an integrity-in-government platform.

"To the public, it doesn't have to be wrong if it has the appearance of being wrong," said McGuirk. "I think it puts the governor in a very awkward position."

Hughes' press secretary, Lou Panos, fired back at McGuirk's criticism. "Harry McGuirk described Harry Hughes in the last election campaign as 'a lost ball in high grass' and then was humiliated by the fact that Harry Hughes swept his district," Panos said.

McGuirk and others questioned several features of the contract, including a provision that the state, if it cancels the contract, must pay Systems Control the cost of any property, equipment or supplies that the firm cannot sell. That sum will grow as the contractor continues to spend money to get ready for the January 1983 start-up date. Several other states with similar inspection programs have given contractors the same protections, because of the high cost of setting up an inspection operation, according to officials in those states.

To limit Maryland's liability, some senators are supporting a resolution to put the contractor on notice that the legislature may soon repeal the 1979 law mandating the program.

Some legislators now say that they supported the bill then to avert a cutoff of federal funds. They predict that President Reagan is unlikely to punish states for failure to comply with the Clean Air Act, and may attempt instead to relax the requirements. Hughes contended, however, that Congress may not change the law, and Maryland may lose millions in federal highway aid.

Such controversies do not fluster Ron Lanchester, an executive of Systems Control, who says his firm has watched similar legislative fights in three other states.

"The whole process doesn't surprise me," said Lanchester. "When every legislature meets, this is something that comes up . . . At this point, nobody knows what the Reagan administration is going to do. We are moving ahead as rapidly as possible."