Last June, Abraham D. Sofaer took off the robes of a federal district judge in New York City, rolled up his sleeves and moved into the sixth-floor office of the legal adviser at the State Department. Nine months later, packing boxes are still piled on the office floor and the ebullient Sofaer is deeply engaged in making policy as well as law for U.S. diplomacy.

State Department veterans said the 47-year-old Sofaer is far more of an activist and key player on policy decisions than any of his recent predecessors. He is one of those rare people in Washington who has become more important than the official post he fills. Sofaer also is more controversial at Foggy Bottom and in the legal community than is usual for a State Department lawyer.

"The policy comes first with Sofaer and then the law," said a senior official. "It's been the other way around with most of the lawyers who've had the job. And besides, Sofaer seems to have views on just about everything."

"The Judge," as Sofaer continues to be called at State, responded to the statement that he values policy over law by citing songwriter Sammy Kahn's remark that it is impossible to say "what comes first, the music or the words."

"In some instances you are told what your principals, or clients in the building, would like to do. In that sense the policy comes first," Sofaer said in a recent interview. "Just like any lawyer who serves his client well, you try to do it. And if you can do it you figure out a proper way to do it.

"On the other hand, if you can't do it you tell them . . . . Many times things have been proposed for action in the department and I have said, 'No' unequivocally. Some of these things have to do with the use of force. Other ones involved ethical-type things, such as can we help some private company?"

According to accounts by several officials, Sofaer's predecessor, Davis R. Robinson, spoke in negative terms too often to Secretary of State George P. Shultz. They cite his repeated arguments against U.S. refusal to participate in the hearing of Nicaragua's case before the International Court of Justice when Nicaragua charged that U.S. paramilitary actions aimed at that country violated international law. Shultz "noticeably reddened with irritation" during one meeting on the subject, according to a participant.

Sofaer, a registered Democrat who was appointed to the federal bench by President Jimmy Carter in 1979, presided over former Israeli defense minister Ariel Sharon's libel case against Time magazine for more than two months in 1984. Earlier, Sofaer was an assistant U.S. attorney in Manhattan, and he has long been known in his profession as a scholar and prolific writer. From 1969 to 1979, he was a Columbia University law professor; in 1976 he wrote, "War, Foreign Affairs and Constitutional Power, Vol. I: The Origins."

Sofaer was looking for another public service challenge last year when Shultz was in the market for a new legal adviser. Sofaer, saying he was impressed with the Reagan administration, changed his party registration to Republican after coming to Washington.

Sworn in last June 9 as State Department legal adviser, Sofaer had hardly learned his way around the building and had just begun to know the 90 lawyers on his staff when TWA flight 847 was hijacked in the Middle East. The new legal adviser jumped into the policy making about how to handle the hostage saga, working almost round the clock for days.

"We successfully used law" to help free the TWA hostages, Sofaer said recently, citing "the very important distinction between bargaining and negotiating" to win release of those being held. "We did not bargain with the hijackers but we did negotiate through Syr-ian President Hafez Assad. We were able to represent to Assad that we would advocate the release of the Shia prisoners" who were being held in Israel and whose release was a key demand of the hijackers.

Sofaer argued a "creative" use of this position did not represent giving in to terrorism, because two years earlier the State Department had objected to Israel's imprisonment of the Shia captives as a violation of the Geneva convention on treatment of prisoners of war. "We did not have to say anything we hadn't said before," he recalled.

The subjects that have engaged Sofaer most since last summer have tended to be those on which his boss has the strongest views. First and foremost has been international terrorism. Sofaer, for example, gave his opinion that intercepting an Egyptian airliner with the hijackers of the Italian cruise ship Achille Lauro aboard was permitted under international law. And after the airliner was forced down, Sofaer drew up extradition papers in an unsuccessful attempt to convince Italian, Yugoslav and Iraqi authorities to hold Abu Abbas, a Palestinian identified as mastermind of the hijack plot.

Sofaer also was an architect of the "Shultz doctrine," the secretary of state's Jan. 15 statement that the United States has a legal right to use military force against terrorists or states that support or encourage terrorists.

Another Shultz passion has been strong opposition to the widespread use of polygraphs in the State Department and other U.S. agencies. Sofaer helped advance Shultz's objections with antipolygraph legal memos, some of which Shultz sent to President Reagan.

Sofaer now is at work seeking a legal position that would halt denial of entry visas to the United States on ideological grounds, as promised by Shultz in a Jan. 12 speech to the PEN International writers conference.

Sofaer's analyses of another controversial issue helped advance a new legal interpretation of the 1972 Antiballistic Missile treaty, which in theory would permit more latitude in testing Reagan's Strategic Defense Initiative.

Last December, Sofaer led a delegation to Israel that worked out U.S.-Israeli cooperation in handling the Jonathan Jay Pollard espionage case. Sofaer, born in India to a Jewish family that originated in Iraq, frequently vacations in Jerusalem, where his wife's family owns an apartment.

His ties to Israel have attracted comment in recent days because of an interview in the Israeli newspaper Haaretz, which quoted him as saying that Israel's war in Lebanon was "justified." Sofaer said he was speaking only in general and theoretical terms about the right of self-defense, and did not "justify" the Israeli action. The State Department said Sofaer's remarks were quoted "inaccurately and out of context."

Reflecting on his career, the activist of the lawbooks said, "It's quite an amazing story for a young Middle Eastern Jewish kid who was born in Bombay to end up being a federal judge, a federal prosecutor and legal adviser. America is really unbelievable."