The Senate voted yesterday to forbid the use of federal funds to pay for abortions, except where pregnancy would endanger the life of the mother, or was deemed "medically necessary" by the woman's doctor, or had been caused by rape or incest.

The words "medically necessary" were written in by Sen. Edward W. Brooke (R-Mass.) after a long series of votes in which the Senate sought to define exemptions more clearly.

Richard S. Schweiker (R.Pa.) called the "medically necessary" term a "barn-door loophole" because he said it would allow any doctor to decide that a woman needed an abortion on any physical or psychological grounds, without guidelines being spelled out.

Adoption of the Brooke language came after the Senate rejected, 56 to 42, a move by Robert W. Packwood (R-Ore.) to kill the entire anti-abortion section and allow continued funding of abortions under the Medicaid program without restriction.

After defeat of the Packwood move, Brooke offered his "medically necessary" language as a substitute for several specific exemptions recommended by the Appropriations Committee.

It was adopted, 56 to 39, despite further complaints from abortion foes that the concept "medically necessary" was so broad and permissive that it almost nulllified the anti-abortion language in the rest of the provision.

The House on June 17 voted to ban federal funding of all abortions - without any of the exceptions allowed by the Senate provision - as part of the $60.6 billion funding bill for the Departments of Labor and Health, Education and Welfare. The Senate vote makes it certain that the final bill will contain an anti-abortion provision in the fiscal year beginning Oct. 1. But the precise scope of the final cutoff must be worked out in a House-Senate conference.

Neither the House nor Senate language forbids a woman to have an abortion under non-government auspices, as long as she pays for it herself. The language applies only to federal funding of abortion under Medicaid programs for low-income women.

Emotions on the issue, already deeply inflamed by religious and ethical questions, were heightened by a Supreme Court decision earlier in the day which seemed to indicate that Congress can constitutionally refuse to finance abortions under Medicaid. A congressional ban on Medicaid funding of abortions, voted last year, had been held in abeyance by the courts.

Jake Garn (R-Utah) asserted angrily that abortion "is the taking of human life."

Jesse Helms (R-N.C.) called abortion "deliberate termination of an innocent human life . . . A requirement that taxpayers furnish the money to terminate innocent human life . . . killing a group of human beings. . . . I don't think she [a pregnant woman] should have the right to use tax funds to terminate another life for her convenience."

Packwood, who attempt to strike out the anti-abortion league but lost, said the ban would in practice rob low-income women of the right to choose whether to have an abortion, because they can't afford it privately. It would be a case of "one section of the country that holds strong feelings imposing it morality on others . . . a disdainful, haughty arrogrance that shouldn't demean this Congress . . . It is not the business of a government to put its particular stamp of morality on abortion."

Brooke said, "If we do insist on denying poor women the funds for abortions, we shall not prevent abortions among poor women. We shall only be forcing them again into dangerous self-induced or back-alley abortions . . . through coat-hanger, lye, a quart of alcohol, an 'accidental' fall."

An amendment by Helms yesterday to eliminate all exceptions to the bill's anti-abortion language except the one involving danger to the mother's life was beaten overwhelmingly, 65 to 38. The Carter administration favored the Helms language, which would have been a substantially stronger ban on federally funded abortions than the language actually adopted by the Senate.

The Senate provision specifies that federal funding of inter-uterine devices and "morningafter pills," would be allowed.

Although the Senate language does permit federally funded abortions where ther is a medical need, as specified in the exemptions, it would block Medicaid abortions for the ordinary, woman who simply wants one because she chooses not to have the child. The federal government helps pay for about 300,000 abortions annually under the Medicaid program, at a cost of $50 million.

Because it was attached to an appropriations bill, the anti-abortion language voted last year expires automatically on Sept. 30. That language was identical to what Helms wanted in the bill. The question in yesterday's debate was whether to extend the ban in some form for another year in the money bill.

In last year's Senate debate, Packwood was successful in striking out all anti-abortion language though it was eventually restored in conference. Heavy lobbying by anti-abortion groups, President Carter's stand in favor of curbs on federal abortion funding and the inability of senators to shelter behind the Supreme Court and say, let's not decide until the court has ruled, influenced yesterday's outcome.