The Senate yesterday passed the first major revision of U.S. immigration law in 30 years, a bill that would give amnesty to millions of illegal aliens who arrived before 1977, but would put new controls on future flows of people across U.S. borders.

These range from the possible issuance of a new national identity card for all workers to fines and jail terms for employers who knowingly hire illegal aliens. The bill also includes a nonbinding provision declaring English the country's official language.

The final vote, 81 to 18, belied the intensity with which these and other issues were debated for months by a shifting series of contradictory coalitions of right and left, farmers and farmworkers.

Part of a public backlash against a rising tide of political refugees in recent years and a flow of illegal alien workers that most officials describe as out of control, the bill, which now goes to the House, would:

* Grant automatic amnesty to illegal aliens here before Jan. 1, 1977, and provisional amnesty to those here before Jan. 1, 1980. Estimates of illegals in this country range from 3 million to more than 6 million. No one knows for sure.

* Establish fines and jail terms for employers who knowingly hire undocumented workers. Employers hiring fewer than four illegal aliens would be exempt, an umbrella that covers about half of all U.S. employers, according to Sen. Alan K. Simpson (R-Wyo.), who guided the bill to passage. An amendment by Sen. John G. Tower (R-Tex.) to weaken the sanctions section was rejected yesterday, 85 to 14. Also rejected was an amendment by Sen. S.I. Hayakawa (R-Calif.) to require federal agents to obtain search warrants before going after illegal aliens on farms.

* Expand the guest-worker program, in which aliens are granted temporary work permits for specific jobs, as a palliative to employers who contend that other restrictions will vastly reduce the pool of foreign workers available.

* Direct the president to develop within three years a fraud-proof system for establishing a worker's identity, possibly a new type of identification card -- a proposal bitterly opposed by civil liberties organizations.

* Set a cap on legal immigration at 425,000 per year.

* Prohibit amnesty recipients from getting federal aid benefits for three years, but authorize block grants totaling $1.4 billion to states with large numbers of aliens to provide emergency care.

The bill contains a nonbinding, sense-of-the-Senate provision decreeing English as the "official" language of the United States, a move that sponsor Hayakawa said was intended, among other things, to put an end to bilingual ballots in states such as his.

None of this came easily. For almost a week, the Senate droned through 20 hours of debate, dealing with 17 amendments and 31 roll calls to produce a bill strikingly similar to a measure before the House Judiciary Committee.

And the intensity of it formed unusual coalitions. On final passage, for example, conservatives Jesse Helms (R-N.C.) and Tower, who thought it too permissive, were aligned with the likes of Edward M. Kennedy (D-Mass.) and Gary Hart (D-Colo.), who found it too restrictive.

The U.S. Chamber of Commerce and the American Farm Bureau Federation were united with the American Civil Liberties Union and Hispanic organizations such as the League of United Latin American Citizens in opposing key sections of the measure.

Kennedy, who led the liberal opposition to the bill, said that "what started out to be immigration reform has become, in too many provisions, immigration restriction . . . that will inevitably be harmful to our country's historic commitment to a fair and reasonable immigration policy."

But Simpson, who parried thrusts from left and right for months, did not contend that the bill was the ultimate answer to a problem he termed "out of control." He said, "This bill isn't perfect, but it's a small start. The issue will be with us, whether we like it or not, for the rest of our history."

Action now turns to the House, which was urged yesterday by Attorney General William French Smith "to act swiftly, in the same spirit of reason and reform." Smith praised the Senate legislation as "historic."

Rep. Romano L. Mazzoli (D-Ky.), chairman of the House immigration subcommittee, said the Judiciary Committee will take up its nearly identical version early next month. Mazzoli and Simpson have worked closely for more than a year to draft their consensus bill.

"The legislation has great appeal across the board, except for the far left and the far right," Mazzoli said. "I am optimistic that we can complete action this year, but it is going to be touch and go. Time is our only enemy on the House side."