President Reagan signed legislation yesterday to end a costly four-day-old rail strike after the House rushed its approval of the measure on an overwhelming 383-to-17 vote.

"There are many elected officials in Washington, and I am one of them, who prefer to keep the government out of the collective bargaining process," Reagan said in a statement. "But we are also committed to protecting the vital national interest."

The strike could have cost the U.S. economy almost $1 billion a day if it continued, "and by far the most important consideration for me is jobs," he said.

The order began the return of trains to service by forcing a no-strike settlement on the 26,000 striking members of the Brotherhood of Locomotive Engineers.

Railroad officials said they were standing by to call work crews back as soon as the president signed the bill. They said that some trains would resume running within minutes of the signing and that full service would be restored within 24 hours.

An Amtrak spokesman said passenger service would be restored today south of Washington and south and west of Chicago, except for instances where the route requires more than one day's travel. The strike had left passenger service largely unaffected in the Northeast.

The union indicated that it would abide by the congressional mandate, approved by the Senate on a voice vote Tuesday night.

The joint resolution, requested by the administration Monday, after mediation efforts reached an impasse after an imposed 60-day cooling-off period, orders the union to agree to a settlement recommended by a presidential emergency panel. The same terms, including a no-strike provision, have been accepted by 12 other rail unions.

House leaders echoed those in the Senate in expressing distaste for intervening in the collective bargaining process, but said the nation could not afford otherwise.

Chairman John D. Dingell (D-Mich.), who steered the legislation through his House Energy and Commerce Committee, presented a litany of dire consequences that mounted even as the House debated: auto plants and steel mills shut, shipments of grain and other perishable goods halted at harvest time.

Many legislators, including some friends of labor who opposed imposition of a settlement, said they felt the issue that prompted the walkout was too narrow to justify its punishing effects on other Americans.

Rep. James J. Florio (D-N.J.), who pushed unsuccessfully for an extended cooling-off period and further negotiations, voted for the settlement order.

The strike, which began at 12:01 a.m. Sunday, had halted most freight traffic around the country. Several coal mines and at least one auto plant were shut, and an estimated 500,000 workers were idled.

Although interference with the right to strike was mentioned often during the debate in both houses, organized labor reacted pragmatically to the action.

"We don't like the government interfering," AFL-CIO spokesman Murray Seeger said. "But, number one, the economy, showing none of the rosy signs of recovery described by the administration, can't afford a strike of such devastating effect. And, two, the engineers never asked us."

The engineers' union is an independent union not affiliated with the labor federation.

One source said AFL-CIO officials had kept in touch "since the beginning of this" with Transportation Secretary Drew Lewis, who was spearheading the administration plan.

The settlement calls for a 28.8 percent wage increase over 39 months, retroactive to April, 1981. The engineers' average annual wage, $36,000, will rise to $45,000.

Negotiating reached an impasse on the engineers' wage advantage over other train crew members. Conductors earn an average of $32,000 annually, and brakemen $27,000. To maintain that advantage, the engineers refused to give up the right to strike.

The dispute stems from redistribution of money, known in some cases as "lonesome pay," and saved when management persuades a union to eliminate unneeded personnel on rail crews. In this instance, bonuses paid to non-engineers on this basis could raise their pay above that of engineers.

John Sytsma, president of the engineers' union, said in a statement yesterday that as soon as the president signed the order and after "the railroad industry furnishes us with assurances that all of our members will be restored to service with seniority unimpaired, no reprisals and carrier promulgations temporary work rules posted during the strike pulled down, we will issue instructions for our members to return to service."

"It is unfortunate that the Congress was forced by the stalling tactics of the railroad industry to pass a law to end our strike. This law by no means solves the basic problem. It must be met somewhere down the road.

"We remain dedicated to the principle that the locomotive engineer must remain the highest paid member of the crew."

Reagan and Lewis praised Congress for acting "promptly, wisely and decisively to end the rail strike."

"It is . . . a fair and equitable solution to the problem," Lewis said.