Robert Sweet, 45, of Dublin, N.H., has been a science teacher, a textbook salesman, a congressional candidate and the head of New Hampshire Citizens for Morality, a Moral Majority affiliate.

But in recent weeks he has performed one of the nimblest bureaucratic end runs in recent memory, placing himself in control--at least temporarily--of the government's main educational research arm, the National Institute of Education.

In the process, he has left his putative bosses at the Department of Education, several senators, fellow bureaucrats and educational lobbyists shaking their heads in amazement, envy and disgust.

Sweet has been a bureaucrat only 20 months, but he has learned fast, using his conservative connections to maximum advantage.

A longtime Reagan supporter, he came to Washington in July, 1981, as a mid-level staff assistant in the Education Department.

But his story really begins last June, when he was named acting director of the NIE after Education Secretary Terrel H. Bell fired NIE Director Edward Curran, another New Right figure, for writing a letter to the White House, recommending that the NIE be eliminated.

Sweet lobbied long and hard to be named the institute's permanent director, but he didn't get the job. Instead, it went to Manuel J. Justiz, who had an enviable resume.

He was a conservative Republican Hispanic, and, unlike Sweet, he had academic credentials and the support of Senate Budget Committee Chairman Pete V. Domenici (R-N.M.).

Sweet, however, refused to give up without a fight. According to congressional sources, he lobbied against Justiz on Capitol Hill and persuaded his old friend, Sen. Gordon J. Humphrey (R-N.H.), to hold up Justiz' confirmation until the last day of the lame-duck session in December.

In January, when Justiz became the fifth person to head NIE in 2 1/2 years, Sweet was demoted to deputy director and told he would be shifted to another job. It was then he began his end run.

When the Senate confirmed Justiz, it also confirmed 12 new members of the National Council for Education Research (NCER), a group that technically oversees the NIE, but in the past has simply been an advisory body.

Sweet persuaded George Roche, the new chairman of the council and president of Hillsdale College in Michigan, to hire him as the council's executive director.

And, when the group held its first meeting on Feb. 18, it passed a series of controversial resolutions which, in effect, put Sweet back in control of the NIE, with his own staff and $834,000 of the agency's budget at his disposal.

The resolutions limited Justiz' authority to hire staff, required him to open all of Justiz' meetings to Sweet, and set aside 1.5 percent of the NIE's budget for the council.

A "fact sheet" on the controversy prepared by the American Educational Research Association alleges that the resolutions are "clearly designed to harass the director, create a New Right think tank within the department and help NCER's executive director to gain power over the agency which he lost when not selected for the directorship."

Justiz has yet to agree to abide by the resolutions. They are now under legal review, "and in a little bit of a holding pattern," Allan Wilson, Justiz' executive assistant, said yesterday.

"The director is more upset about the appearence of the situation than the reality at this point," said Wilson, adding that Bell ultimately may have to resolve the situation. "In a big way, the ball is in the department's court and not the institute's."

Spokesmen for Bell did not return repeated telephone calls for comment yesterday.

Meanwhile, some members of Congress are beginning to regard the controversy as an embarrassment for the Reagan administration.

Sen. Robert T. Stafford (R-Vt.), chairman of the Senate Labor and Human Resources subcommittee on education "is going to exercise his oversight responsibility" and move to eliminate the council if that becomes necessary, a subcommittee spokesman said yesterday.

"The recent actions have limited the ability of the secretary and the NIE director to carry out policy," he said.

For the time being, Sweet is at work in new offices at 19th and M Street NW. He said he got where he is through hard work. "Whatever I do I do with vigor," he said yesterday. "I leave home at 6:30 in the morning and don't leave until 7:30 at night. I'm a real student of the system and I've tried to make it work for me.

"I'm here because I want to make a difference and help Ronald Reagan carry out his mandate."