A last-minute assault by labor unions, agribusiness groups and Hispanic and black organizations is threatening to derail the comprehensive revision of the nation's immigration laws, scheduled to be considered by the House in the next two weeks.

The legislation, passed by the Senate in July and by the House Judiciary Committee in September, is the first major rewriting of the government's tangled immigration policy in 30 years. However, the issues involved in dealing with the massive influx of illegal aliens and foreign workers are so politically explosive that few members of Congress expect the bill to be enacted this year.

Ray Denison, chief lobbyist for the AFL-CIO, served notice that the labor federation would oppose the legislation unless "there is assurance" that the Justice Department and a majority of House members support restrictions on importation of foreign temporary workers, approved by the House Education and Labor Committee last Wednesday.

House Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.) said late last week that AFL-CIO President Lane Kirkland had originally called him to push the bill, as have religious groups. "Because of that, the leadership sat down and decided to take it up," O'Neill said. "Then we were notified a day later that labor opposes. We still hope to schedule it."

Romano L. Mazzoli (D-Ky.), chairman of the House immigration subcommittee, said House Rules Committee members, scheduled to vote on the bill Tuesday, are "under a lot of pressure with letters, threats, cajolery and promises.

"The interest groups failed at every step to stop the bill. Now they sense it has a momentum, a righteousness, a timeliness. They're trying to kill it rather than perfect it."

The bill is a precariously constructed compromise granting amnesty in the form of permanent residency to qualified illegal aliens who have lived in this country since Jan. 1, 1977. To discourage future illegal immigration, the bill imposes sanctions on employers who knowingly hire undocumented workers and makes it easier for the government to deport aliens.

"Both the right and the left are moving away from the consensus on this bill," Barney Frank (D-Mass.) said. "There's a lot of pushing and pulling, and so many things are so delicately balanced that it may be undoable."

An effort to delete the amnesty provisions and add a guest-worker program is being led by Sam B. Hall Jr. (D-Tex.) and other conservatives, representing farmers who employ Mexican labor.

"We have thousands of people trying to get into the United States on a legitimate basis," Hall said. "Now, with a stroke of the pen, we're telling people who are here illegally that they can stay. That plays havoc with our entire immigration program."

Unions favor amnesty on the premise that legal workers can be organized more easily than illegal workers. That is precisely the reason that growers oppose it.

Judiciary Committee Chairman Peter W. Rodino Jr. (D-N.J.) has pledged that, without amnesty, there will be no bill. "There are millions of people here in an underclass," Mazzoli said. "They've got roots in the community. They've done our grungy work. This country won't stomach a massive deportation. We've got to do something."

Farmers and Hispanic groups oppose the employer-sanctions provisions, the Hispanics because they say sanctions would result in discrimination against them. Blacks fear that loosening the rules would permit easier deportation of Haitian refugees.

The section of the bill incurring unions' wrath, however, is an expansion of the Labor Department's "H-2" program, which allows about 40,000 temporary workers into the country annually. Under the House bill, a compromise designed to fend off a full-fledged, guest-worker program favored by the administration, as many as 300,000 temporary workers could come into the country, Denison contends.

"At a time of high unemployment, this would be a totally uncontrolled guest-worker program," he said. "We're asking the House leaders to take a nose count and make sure before they take the bill to the floor that a majority of House members support" restrictions on the program passed by the Labor and Education Committee.