Four Palestinian terrorists shot their way into the Egyptian Embassy here today, killing two policemen and taking about 20 persons hostage, including the Egyptian ambassador and military attache.

The gunmen demanded that Turkey break diplomatic relations with Israel and Egypt and formally recognize the Palestine Liberation Organization. They also demanded that Egypt release two Palestinians it has sentenced to life imprisonment on terrorism charges.

The Egyptian government, outraged at the attack on its embassy, served notice tonight that it holds the Palestinian guerrilla movement responsible and promised "strong retaliatory measures against the aggressors."

[Two hostages were badly injured early Saturday when they jumped from the top floor of the embassy, Reuter reported. Two other hostages, commercial attache Ismail Mohammed Abdul Halil and his assistant, Halif Ibrahim, escaped with minor injuries, according to other reports.]

The takeover was the most serious terrorist strike against an Egyptian target since President Anwar Sadat signed the peace treaty with Israel on March 26. It marked another escalation in the campaign by hard-line Arabs to punish Sadat for his willingness to break Arab ranks and end hostilities with the Jewish state.

One of the terrorists told Turkish radio by telephone tonight that "we are determined to blow up the building" if the demands were not met Turkish radio said, however, that Ambassador Ahmed Kemal Olema and the other Egyptian hostages had not been harmed.

Late tonight, more than 12 hours after the midmorning attack, Turkish police and troops with armored vehicles remained in position around the embassy building.

Egyptian Prime Minister Mustafa Khalil authorized Turkey to use militar force to take control of the building, but it appeared Turkey was prepared to wait.

By emphasizing that Egypt blames all factions of the PLO, Khalil implied skepticism at a claim from PLO spokesman Mahmoud Lebadi in Beirut that Yasser Arafat's mainstream guerrilla movement was not involved.

Reports from Beirut said a caller told newspapers there that a group called the "Eagles of the Palestinian Revolution" had carried out the Ankara attack. The group is little known, however, and its leaders have never been convincingly identified.

The raid on the embassy began just after the morning rush hour. Four gunmen got out of a taxi and opened fire on Turkish policemen guarding the building.

They shot the lock off the main gate and rushed up the stairs and across the lawn, still shooting. At the entrance they threw two bombs and fired on other policemen.

Two policemen were killed and another was wounded. There were no indications of injuries among the attackers.

A few hours after they seized the embassy, the Palestinians released a Turkish secretary. She came out carrying a white flag and shouting, "Don't shoot, I am Turkish." She was taken to Turkish Interior Minister hasan Fehmi Gunes, apparently with a message from the terrorists.

Just before midnight, the Palestinians accepted food and aspirins, which were bought to the embassy in an armored police vehicle. A police officer left the packages at the chancery door.

Turkish Prime Minister Bulent Ecevit held an emergency Cabinet meeting and later joined Gunes, Foreign Minister Gunduz Okeun and military officials at a command post near the occupied embassy.

In addition to the demands relating to Egypt, Israel and the freeing of prisoners, the attackers also asked for free passage out of Turkey for themselves and their hostages and they called on Turkey to "condemn American imperialism."

It is considered highly unlikely that any of the demands will be met. Turkey has a tradition of not giving in to terrorist demands.

Six years ago 11 Turkish Communist guerrillas were killed by troops in a village house where they held hostage two Britons and a Canadian NATO technician. The guerrillas killed the Canadian before they died.

Ecevit's government is fighting a plague of political violence at home that has claimed more than 1,400 lives in Ecevit's 18 months in power. He is considered unlikely to set an example of buckling under, which might be exploited by Turkish extremists of the right and left.

Three years ago Turkey gave the PLO tentative permission to open an office in Ankara but it has never given final permission. One reason, observers believe, is that some Palestinian organizations provide training for Turkish terrorists.

Although maintaining diplomatic ties with Israel, Turkey supports the cause of the Palestinian people and has upheld U.N. resolutions in their favor.

Turkey criticized the Egyptian-Israeli peace treaty as an accord that would not help solve the overall Middle East problem.

Many Arabs and Palestinians, however, have criticized the Turkish position as lukewarm.

Many Arab states, ranging from Libya to Saudi Arabia, have put pressure on Ankara to sever its ties with Israel and get more actively involved on the Arab side.

The Turks persisted in maintaining their distance despite tempting offers of cheap crude oil.

Egyptian Prime Minister Khalil indicated in Cairo that Egypt might seek to strike back at the Palestinians.

"Egypt holds the Palestine Liberation Organization, with all its factions, responsible for the incident, which affects its basic relations with the Egyptian people," he said. "There will be serious retaliation if anything happens to members of the embassy staff or the embassy property."

In a later telephone conversation with correspondents, Khalil ruled out any Egyptian commando raid such as the disaster that followed an attack on Egyptians in Nicosia, Cyprus, last year. Fifteen Egyptian soldiers were killed in the attack. But he reiterated that Egypt plans "strong retaliatory action" against the Palestinians blamed for the Ankara attack.

It was unclear, however, what Egypt could actually do against the PLO. The overall guerrilla organization already has broken relations with Egypt because of the peace treaty with Israel. Its Cairo office officially has ceased to function, although PLO representative Saeed Kamal continues to reside in Cairo, stripped by Arafat of his PLO credentials.

There was no sign that Egypt was prepared to release the two prisoners whose freedom was demanded by the terrorists in Ankara. The official Egyptian Middle East News Agency reported tonight for the first time that the pair recently was sentenced to life in prison.

The two were arrested in April at Cairo airport and accused of plotting to carry out terrorist attacks in Egypt. Both were said to be from the "Eagles of the Palestinian Revolution," the group reportedly responsible for the Ankara attack.

Some Beirut newspapers usually well informed on Palestinian Affairs have reported that the group is an off-shoot of Saiqa, the Syrian-backed commando group headed by Zohair Mohsen and generally considered to function as an unofficial arm of the Syrian armed forces.

But this has not been confirmed. Other sources have speculated that the Eagles are simply another manifestation of the Black September terrorists who organized the 1972 Munich Olympics attack on Israeli athletes. CAPTION: Map, no caption, By Dave Cook - The Washington Post; Picture, Turkish police take positions outside the Egyptian Embassy in Ankara, where terrorists were holding 20 hostages. UPI