Israeli Prime Minister Menachem Begin was rushed to the hospital after having a heart attack this afternoon, just before the parliamentary opposition barely failed in an attempt to vote his beleaguered government out of office.

Since 1977, Begin, 66, has suffered a massive heart attack, subsequent complications and a light stroke. He was taken to the cardiac intensive care unit of Hadassah Hospital in an ambulance.

Begin's personal physician, Dr. Mervyn Gottesman, said the prime minister suffered a "slight heart attack" or "myocardial infarction."

Gottesman added that 24 hours were needed for a more accurate diagnosis. "The severity of the attack was difficult to determine," he said.

Gottesman said this attack was not in the same region of the heart as the massive attack that Begin suffered a few months before his May 1977 election victory.

He described Begin's condition as "fair" and said the prime minister was sleeping after a "strenuous day."

Although the prime minister insisted he was feeling "very well," Gottesman said Begin would remain hospitalized for several days for observation.

Begin, who was conscious throughout the attack, appointed Deputy Prime Minister Yigael Yadin as acting prime minister and defense minister.

Yadin filled in for an ailing Begin on two previous occasions -- in June 1977 when the prime minister was hospitalized with complications from the massive heart attack in February of that year and again last July when Begin had a mild stroke affecting his peripheral vision.

Witnesses at the Knesset (parliament) said that just after 4 p.m. Begin showing signs of discomfort, removed his tie, and wiped perspiration from his brow as he and Yadin sat on the government benches.

Yadin asked him if he was not feeling well and slipped out of the chamber briefly. He returned, helped Begin to his feet and then supported him as they walked to the prime minister's office.

Gottesman arrived within minutes and administered oxygen and first aid. Begin reportedly wanted to return to the chamber to take part in the vote, but Gottesman ordered him hospitalized.

In Begin's absence, the government coalition defeated by a vote of 60 to 54 an opposition motion demanding that the Knesset be dissolved and new elections held now rather than in October 1981 when the present government's mandate expires.

The government's popularity has plummeted largely because of inflation, which now is running at nearly 200 percent per year.

Political analysts said the vote was closer than expected.

Begin has shown his determination to see his administration through rather than call elections now.

Shmuel Toledano, a member of the Shai parliamentary group that presented the motion, said the vote underlined the Begin government's narrow majority in the 120-seat Knesset.

Toledano said, however, he did not expect the government, which gradually has been losing supporters, to fall soon.

Toledano contrasted the growing lack of support for Begin in the country with the bare majority the government mustered today.

Technically, the opposition motion was not a no-confidence vote. Such a vote would have forced wavering members of the coalition to betray promises of support for the Cabinet that they gave when the government was formed in 1977.

The motion actually did not mention the government at all, but asked members of the Knesset to dissolve the body and order new elections.

Indicative of the mood among Begin's core supporters in the Likud movement was their effort to play down his illness. As rumors swept the Knesset that Begin had fainted, the Likud stalwarts insisted he was simply suffering from "heat and fatigue."

Only yesterday, BEGIN presided over the weekly Cabinet session in what was described as "feisty" spirits.

Last September, Begin's office dismissed as a "fabrication" a Time magazine article stating that a three-member medical panel had recommended that Begin restrict himself to a three-hour workday.

meanwhile, an Israeli force raided a Palestinian base in southern Lebanon before dawn Monday, blowing up houses and killing a number of Arabs, the Associated Press reported from Tel Aviv. The Palestine Liberation Organization said the Israelis killed 11 people, including four children and two women.

A PLO spokesman said the Israeli attack took place near Qasmieh Bridge, about 17 miles north of the Israeli border.)

however, an Israeli military spokesman said troops blew up five houses and met no resistance at its target, about five miles north of Tyre.) He said the force did not suffer any casualities.

[in another development, Egypt's air defense commander said today that country's air defense system will be equipped soon with an advanced version of U.S. ground-to-air Hawk missiles), new agencies reported from Cairo. Maj. Gen. Sayed Hamdi told a news conference that Egypt also would get other modern U.S. equipment to raise the efficiency of air defense.]