The Senate, debating a major immigration reform bill, narrowly defeated an attempt by Sen. Pete Wilson (R-Calif.) yesterday to expand the flow of foreign agricultural workers into the United States to harvest perishable crops.

The bill's chief sponsor, Sen. Alan K. Simpson (R-Wyo.), noting that the legislation already liberalized the rules for foreign farm workers, said the Wilson amendment would be a "serious error."

The amendment was defeated on a 50-to-48 vote. It would have allowed an unspecified number of workers to enter the country for up to nine months to harvest perishable crops. To help ensure that the workers did not stay, 20 percent of their wages would have been withheld, then given to them at U.S. consulates when they went home.

Wilson said that Americans are not willing to perform the jobs, and that the current system gives farmers the choice of "breaking the law or losing the farm."

Sen. Steve Symms (R-Idaho) supported the amendment, saying it would "help out humanity . . . . Without this amendment, we're ignoring what is really going on in the real world outside, where vegetable crops are being harvested . . . . This is good for nationals from Mexico who have a much lower standard of living."

But Sen. Paul Simon (D-Ill.) argued that such a "guest worker" program would "open the door wide open to every possible abuse" of foreign field hands.

The Senate immigration bill would grant legal status to illegal aliens who have lived in the United States since Jan. 1, 1980.

But it would also attempt to slow the flow of illegal immigration by creating civil and criminal penalties for employers who hired illegal aliens. In addition, the legislation would strengthen enforcement by adding financial resources to the Border Patrol and Immigration and Naturalization Service.

Immigration reform legislation has been approved twice by the Senate and once by the House, but died in the closing days of congressional sessions.

Simpson predicted that the bill will be finished by the Senate today and sent on to the House. But several controversial amendments remain to be considered.

One amendment, proposed by Sen. James A. McClure (R-Idaho), would require federal agents to obtain search warrants before looking for illegal aliens in agricultural fields. The administration has opposed the proposal.

Another major question, almost certain to be addressed in the House or Senate, is whether the federal government will pick up the cost of social services for immigrants who acquire legal status under the legislation.

Experts from the Congressional Budget Office estimated this week that there are 5.6 million illegal aliens in the United States. The CBO figures indicate that about 1.4 million aliens would come forward and qualify for the legalization program proposed in the Senate bill at a cost of about $1.8 billion in social services during the next four years.

Several states -- including Florida, Texas and California -- have disproportionate numbers of illegal aliens, but the administraiton has made clear its opposition to expanding categories of public assistance for which the federal government reimburses states and localities.

Another bill, facing subcommittee hearings in the House, would give legal status to illegal aliens who have been in the United States since Jan. 1, 1982.