A federal judge ruled unconstitutional yesterday a Carter administration crackdown on Iranian students in the United States, saying it was illegal to single out one group of aliens for an action that could have led to large-scale deportations.

U.S. District Judge Joyce Hens Green said the administration's order might seem appropriate in view of the "extraordinary international crisis" caused by the "unprecedented violation of international law" involved in the takeover of the American Embassy in Iran, but she termed it an unwise attempt "to foresake briefly our constitutional beliefs and realitites and yield to the moment of time."

The Justice Department filed immediate notice that it would appeal Green's ruling.

The deportation order struck down yesterday was one of several measures taken in response to the Tehran hostage situation, and the Justice Department had argued strongly that it was within the president's power.

Green disagreed, saying the regulation appeared to serve only a "psychological purpose . . . of assuaging the anger of the American people by demonstrating that something is being done in the face of crisis."

Instead, she said, Congress -- and not the president -- might have had the power to pass such a regulation.

She immediately blocked the administration from:

Enforcing the regulation, which required Iranian students to report to the nearest Immigration and Naturalization Service office with evidence of their residence and student status.

Deporting any student who had complied with the regulation.

Using any information gathered in the review of more than 50,000 Iranian students who have already reported under the program.

President Carter asked the attorney general on Nov. 10 to identify all Iranian students in the United States who were not in compliance with their visas, and Attorney General Benjamin Civiletti issued regulations three days later.

Since them, at least 50,547 Iranian students have been interviewed and 41,254 were found to be in compliance with their visas, a Justice Department spokesman said yesterday. Another 4,062 were found to be deportable and cases on 3,212 were still pending awaiting further record checks.

According to the Justice figures, 405 of the Iranian students checked have asked for political asylum in the United States, while 778 agreed to leave voluntarily. Of the voluntary departures, 47 have already left the country. Another nine have been through deportation hearings and were forced to leave.

The ruling came in two suits filed on behalf of Iranian students in the United States and sponsored by, among others, the National Emergency Civil Liberties Union and the Socialist Workers Party. An SWP attorney, Margaret Winter, said after the ruling that it was a "blow to President Carter's vindictive use of the Immigration and Naturalization Service."

Judge Green pointed out that the "violent actions in Iran have not only outraged all Americans but have been universally condemned by other nations throughout the world."

The administration's response, she noted, was based on its belief that the president had wide-ranging power to deal with matters concerning aliens. She pointed out, though, that aliens are fully protected by the U.S. Constitution once they are here.

She conceded that the present Iranian crisis "sorely tests the [Carter administration's] ability to firmly demonstrate this country's willingness to resist this form of international blackmail, while, at the same time, acting in a manner that fully reflects the fundamental American belief in individual liberties applied evenly, dispassionately and justly, with equal treatment for all persons, whether they agree or disagree with the aims of those holding the innocent American citizens in Tehran."

She said the president had an "awesome responsibility," but added that in the immigration area as well as other areas he "must be subject to applicable principles of the Constitution."

Since the classification was based on national origin, she said in her 23-page ruling, it could only be justified by overriding national interests. The government said it was justified because of the need to protect hostages in Iran by quelling potential domestic violence here, the need to express displeasure with actions in Iran, and the need to identify Iranian students in connection with future possible actions.

She said there was a "dubious relationship" between the Iranian students' presence here and possible harm to hostages in Iran, and said any need to express American anger at Iranian actions "is hardly sufficiently compelling to justify subjecting only Iranian students to a disriminatory 30-day roundup that violates the fundamental princples of American fairness. . ."

She said the order would unnecessarily disrupt "the lives of so many who come to this country merely to receive an education with which they could better themselves and their native land.

"To countenance the disparate treatment of Iranian students that the regulation candidly promotes would not only reject the most cherished constitutional precepts applicable to all of us, citizen and alien alike, but would create a precedent of alarming elasticity from which future extreme assertions of executive power could readily springboard.

"Constitutional submission to the wash of emotion would eliminate the fair play and equality that is the quintessence of the American way . . ." she said.