The Senate voted late Friday night to repeal a controversial law that requires American medical schools to admit American students transferring from foreign medical schools or face a cutoff of federal funds.

Thirty-six of 116 U.S. medical schools have declared they would forfeit the federal grants - which amount to a half million dollars or more annually for many schools - rather than comply with the 1976 law, which would go into effect next September.

Yale, Harvard, Stanford and Johns Hopkins have jointly planned to sue the government, challenging the law's constitutionality on the basis that it violates their academic freedom to chose students.

The provision in the 1976 Health Manpower Act requires U.S. medical schools to accept as third-year transfer students those American who have completed two years at foreign medical schools and are designated eligible by the Department of Health, Education and Welfare.

The law prohibits medical schools from applying their own standards for admission. Transfer must pass part or of the examination of the National Board of Medical Examiners to be eligible for admission, but medical schools protest that this standard test is too minimal to be an adequate screening device.

"This Senate action is terrific news and a vote for academic freedom. The Senate at least recognizes it's a mistake for the government to try to tamper with the admissions process," said Richard S. Ross, dean of Baltimore's Johns Hopkins University Medical School. Johns Hopkins was the first school to tell HEW it would forfeit funds - up to $700,000 next year - rather than comply with the law.

The repeal, added by Sen. Charles McC. Mathias (R-Md.) to a bill that would have only modified the law, now goes to conference with the House. A House amendment to the Health Manpower Act would only limit the number of transfer students a school must take.

Medical schools argue that the law also penalizes current students because those attending schools that became ineligible for the grants by refusing to comply with the transfer student provision would lose their eligibility for federal insured student loans.

"It is unconscionable to punish these students," said Estelle A. Fishbein, general counsel for Johns Hopkins.

Supporter of the bill say its intent is to provide the best possible medical training for the thousands of American who fail to win admission to American schools and then enroll abroad. HEW has declared 839 students eligible for trnsfer next fall.

In recent years, the stiff competition to enter American medical schools has led increasing numbers of Americans to enroll in schools in Europe, Asia and the Caribbean. Families of many of the students have organized an intense lobbying campaign seeking to allow them to transfer to U.S. schools.

Major and schools argue that in addition to wanting to apply their own admission standards, they do not have the space to add students.