President Reagan, marking the end of a week of international terrorism directed at the United States and its servicemen, paid solemn tribute yesterday to four marines gunned down in El Salvador and vowed "to find the jackals and bring them and their colleagues in terror to justice."

In a poignant ceremony on the windswept tarmac of Andrews Air Force Base, Reagan pinned Purple Heart medals on the flag-draped caskets as family members sobbed and embraced.

His voice thick with emotion, Reagan told the families, "They say the men who murdered these sons of America disappeared into the city streets. But I pledge to you today they will not evade justice on Earth any more than they could escape the judgment of God."

The president and Nancy Reagan then moved through the line of family members -- 28 parents, brothers and sisters -- and Mrs. Reagan embraced many of the tearful relatives.

The ceremony came at the end of a week of extraordinary terrorist attacks against U.S. citizens and servicemen that has severely tested Reagan's proclaimed doctrine of "swift and effective retribution" against such violence and confronted the president with scenes of sorrow.

It was a week in which Reagan acknowledged the limits of U.S. military power in response to terrorism, including the hijacking of Trans World Airlines Flight 847 in the Middle East and the San Salvador killings. In both cases, Reagan has decided against retaliation that would harm innocent civilians.

Earlier this week, the body of Navy petty officer Robert Dean Stethem, murdered by Shiite Moslems who hijacked Flight 847, was returned to the United States.

Yesterday, the president honored four Marine guards of the U.S. Embassy in San Salvador who were killed, with two other Americans and seven other people, Wednesday as they sat in a sidewalk cafe. Reagan and Marine Commandant Gen. P.X. Kelley, saluted as caskets were carried from a C141 cargo jet transporting the remains of the servicemen from Howard Air Force Base in Panama.

Killed in the attack Wednesday night were Sgt. Bobby Joe Dickson, 27, of Tuscaloosa, Ala.; Sgt. Thomas T. Handwork, 24, of Boardman, Ohio; Cpl. Gregory H. Weber, 22, of Cincinnati, and Cpl. Patrick R. Kwiatkowski, 20, of Wausau, Wis.

An anguished cry of "Oh my God!" from one family member echoed across the tarmac as a breeze pushed the flags from two caskets. Marines quickly stepped forward to replace them.

Reagan, who flew to the ceremony from Camp David, paid tribute to each serviceman. Weber, he said, told his father he wanted to guard the U.S. Embassy because "they need a few good men." Handwork, a five-year Marine Corps veteran, saw his work as "a calling. He wanted to be a Marine from the first days he could walk and talk." Dickson was "raised in a tradition of family honor. He feared nothing." And Kwiatkowski, Reagan said, was the youngest -- his 21st birthday was Friday.

"They were all volunteers," Reagan said. "They were four young men who decided to follow an honored and ancestral path. And so they swung the bag over their shoulder, kissed their parents goodbye, and went off to serve their country.

"They chose to follow the life of service, selflessness and courage. They did it for love and honor," Reagan said, repeating the Marine Corps motto, "Semper Fi."

Reagan promised the families that the U.S. and Salvadoran leaders would "move any mountain, ford any river" to find the terrorists and bring them to justice.

Reagan has rarely attended such ceremonies in his presidency; Vice President Bush attended the arrival of Stethem's body earlier in the week. Today, Reagan was accompanied by Secretary of State George P. Shultz, Defense Secretary Caspar W. Weinberger and national security affairs adviser Robert C. McFarlane.

The president returned to Camp David after the caskets were carried off in hearses and he and his wife again consoled the family members as they boarded Marine buses.

Reagan made no mention during the ceremony of the Americans still held hostage in Beirut.

In his weekly radio talk, Reagan said he and Mrs. Reagan "carry with us all of the grief and sorrow and rising anger of a nation whose patience has been stretched to its limit."

Earlier in the day, Reagan lunched at Camp David with Bush and McFarlane to discuss the situation in Beirut.

Presidential spokesman Albert Brashear said the administration is pursuing contacts that it has previously made to gain release of U.S. hostages, but he refused to elaborate.

Later, at a news conference in Grand Rapids, Mich., Bush said the Camp David meeting was "to discuss how we and our allies can best respond to the terrorist problem. We are concerned about our hostages, but it is not we alone who suffer. Kuwait, Germany, Jordan, El Salvador all have suffered attacks."

Bush, who made a quick political trip before his expected departure today for Europe for consultations with allies, has been assigned by Reagan to examine long-range methods of handling terrorist attacks.

Bush said that on his European trip "I will be discussing with the heads of seven of our closest allies the terrorist problem, the means we share, and the responsibility we have to respond effectively.

"I will return to head a major coordinated effort to see what more can be done by this country and others as well to reduce international terror to its barest minimum."

Bush cited Libya and Iran as governments supporting terrorist activities but he declined to link either country to the situation in Beirut. In a carefully worded statement, he said:

"It has to be acknowledged that the terrorist is now aided and abetted by certain governments who, by sponsoring, aiding, abetting, supplying and training, give the terrorist a range of support which he has not enjoyed before."

Asked if the hostage situation had strained U.S. relations with Israel, Bush said, "I can't comment on that," but added, "I would hope not."

Bush, who came to Grand Rapids to speak to the Republican Midwestern Leadership Conference, defended taking the time out for politics in the midst of a crisis, arguing that it took him only a few hours in one day. Asked how Reagan can afford time for trips promoting his tax legislation, Bush said Reagan "delegates, he leads, and he has very good communications."