The striking railway clerks union bowed yesterday to a federal court order enforcing President Carter's back-to-work directive and agreed to end its crippling four-day strike against most of the nation's railroads.

Fred J. Kroll, president of the Brotherhood of Railway and Airline Clerks, ordered his members back to work shortly after U.S. District Court Judge Aubrey E. Robinson Jr. issued a temporary restraining order against the walkout.

After a one-hour hearing during which the government formally joined the railroads in seeking a back-to-work order, Robinson said he was also imposing a ban a company reprisals against strikers.

The Judge's order came as a surprise, because he had expressed misgivings earlier about his power to act in the dispute.

BRAC had sought full protections against company reprisals and had vowed not to return to work without such guarantees. Kroll was apparently satisfied with the prohibitions that Robinson wrote into his order.

"With this tremendous victory, I urge our people to return to work," he told reporters after reading Robinson's decision. "We got damned good protection against reprisals. We're extremely happy. We're urging everyone to return to work immediately."

Judge Robinson's back-to-back order extends until Oct. 10, when he will hear arguments on a permanent injunction to continue the strike ban.

The strike - the nation's first coast-to-coast rail walkout since 1971 - began July 10 as a local disput between 4,600 BRAC members and the Virginia-based Norfolk & Western railway.

It spread to 43 other railroads handling two-thirds of the country's passenger and freight rail traffic last Tuesday when the union, frustrated in its bargaining over job security and union jurisdiction issues with N&W, sought to generate pressure from other railroads to force N&W to settle.

By yesterday, nearly 70 percent of the nation's 200,000 miles of railway track was under strike and only a few line were left open, according to the Association of American Railroads, Layoffs were beginning in the auto industry, with warnings of massive industrial shutdowns if the strike didn't end immediately.

The administration, alarmed at the strike's potential impact on the economy, intervened on Wednesday, giving the two parties 24 hours to resolve the dispute by themselves. When the negotiations failed, the administration invoked emergency procedures of the Railway Labor Act.

Using that law, President Carter ordered the strikers - by the more than 300,000 in number - back to work on Thursday and vowed during his nationally televised news conference to take legal action to enforce the order.

The initial response from BRAC was to continue the strike, defying the president's order in hopes that the courts would refuse to enforce it. The union was in the process of expanding the strike to several more railroads, when Carter issued his order, and it didn't stop.

At first it appeared that Robinson, who had rebuffed the government in a strike-ending move during the recent coal strike, would side with BRAC in its interpretation of murky language in the Railway Labor Act on whether a president could halt a strike already in process. Normally the act is involked before a strike occurs; its use to end an ongoing strike has not been tested.

BRAC attorneys argued that Carter was without power to order the strikers back to work, and Robinson refused after Thursday night's session to issue a restraining order. He said he doubted that he had jurisdiction but deferred a decision until yesterday, leaving the two sides a few more hours to settle their dispute over reprisal protections.

Attorneys for the union, N&W and more than 100 other railroads that were by then involved in the dispute met for several hours yesterday at the Labor Department but failed to come up with an agreement in time for their late afternoon session with Robinson.

In court, a union attorney indicated that an argeement was still possible, but Robinson, in no mood for further dallying, said, "Your time for an agreement was passed five minutes before you entered this courtroom."

Robinson indicated that his forthcoming written order would spell out reprisal protections. Attorneys for N&W had said the company had "no intention" of conducting reprisals, but union chief Kroll had said strike leaders would be like "sheep led to slaughter" without some court or congressional protections.

BRAC's hop all along has been to involve Congress, which often has had to act to end rail strikes when all other procedures fail. Early yesterday Kroll issued a statement suggesting that "congress might consider seizing the railroads for the duration of the dispute as well as ordering the workers back to their jobs."

While this course was never under consideration by the administration, the White House and Labor Department were prepared to ask Congress to take emergency legislation to end the strike if the government lost in court.

House Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.) alerted congressmen yesterday that the administration, if necessary, might send legislation to Capitol Hill as early as today.

In joining the railroads' request for an injunction, Glenn Whitaker, representing the Justice Department, said any restraining order should be a "double-edged sword," meaning to protect workers while forcing them back to work.

Richard Conway, an attorney for the National Railway Labor Conference, the railroads' bargaining group, said he agreed the order should be "doubled-edged" but urged that the companies not be enjoined from enforcing usual disciplinary procedures of making economic-based layoffs. He said N&W has had some "serious violence" that it wanted to deal with.

BRAC attorney John Clark argued that some strike-related layoffs have already occurred, involving up to 1,000 workers at one company, and said there is a "substantial likelihood" of more reprisals.

Robinson indicated that the temporary nature of the back-to-work order, which is subject to review at the Oct. 10 hearing, may offer some inducement to restrain reprisals.