Officials of Gov. Harry Hughes' administration, deriding a legislative agreement to earmark $3.5 million for Montgomery County roads as "pork barrel" and the product of "back-room deals," rejected the compromise today but said the improvements may occur anyway.

In separate interviews, state Transportation Secretary William K. Hellmann and Hughes' top transit aide, Wayne McDaniel, castigated General Assembly leaders for the highway agreement, which was announced only hours earlier.

House Speaker Benjamin L. Cardin (D-Baltimore) had held an impromptu news conference in his office to announce the agreement with Senate President Melvin A. Steinberg (D-Baltimore County), in which the legislature would add $3.5 million to the 1986 budget for road projects around Maryland. Half of the funds, which were to be added to the budget of Hellman's department, would be used for planning improvements to Rte. 118, a heavily used commuter road in upper Montgomery, the legislators said.

Hellmann and McDaniel said they believe the agreement announced by Cardin has no legal effect and does not mean the governor will use the extra money for the Rte. 118 improvements. But they also noted, as Hughes has in recent days, that the proposed highway work will be reviewed this year and may be accelerated anyway.

Highway funds have been the top legislative priority of Montgomery delegates and senators.

Improvements to Rte. 118 in the county's high-technology corridor "will bring major dividends to the state of Maryland," declared Cardin, who was accompanied at the press conference by Del. Ida G. Ruben (D-Montgomery), head of the county's delegation. Ruben, a vigorous campaigner here for Montgomery road funds, said she was "thrilled" by the agreement.

Hughes, however, was not. When word of Cardin's announcement reached the governor and his staff late this afternoon, they quickly attacked the agreement as a violation of the executive's traditional and legal prerogative over road projects.

Hughes, who is sympathetic to Montgomery's argument that clogged commuter roads are stunting economic growth, called the agreement a "terrible precedent," McDaniel said.

"We have laws that set the process for transportation construction," said Hellmann, adding the agreement was an example of the "nightmare of the legislature promoting pork barrel projects."

McDaniel echoed Hellmann, saying, "It's especially ironic since this was developed by Montgomery County legislators who believe in good government and government in sunshine -- not backroom deals."

One consideration influencing discussions over Montgomery roads is which elected official will be able to claim credit for securing the funds for the county.

Cardin, for instance, took pains to praise the work of Ruben, her Senate counterpart Sidney Kramer (D-Montgomery), and Sen. Laurence Levitan, (D-Montgomery), who chairs the powerful budget committee.