Highway safety administrator Raymond A. Peck, variously accused of being too soft and too hard on the nation's automakers, and often in trouble with the administration he served, yesterday announced his intention to leave the federal government May 21.

Peck's resignation came two weeks after his agency, the National Highway Traffic Safety Administration, released a film of a simulated accident in which the rear-wheel assembly fell off a 1979 General Motors Corp. station wagon, without telling the public the accident was staged to dramatize the agency's concern over a suspected safety defect.

The test-film incident provoked criticism of Peck from the auto industry and within the administration. It was the latest in a series of public relations mishaps, including a 1981 episode in which he discontinued NHTSA publication of the "Car Book," only to see an ex-employe publish the book anyway.

Peck unwittingly publicized the renegade book, a comprehensive guide to car-buying, by going on television to criticize the ex-employe. On another occasion, Peck announced he would censure two senior agency supervisors for failing to control leaks of agency information, and then was ordered to back down by superiors.

More serious controversies centered on major changes in auto safety regulations ordered by Peck involving automatically closing seat belts and impact-resistant car bumpers. Consumer groups and members of Congress accused Peck of weakening safety regulations and undermining the safety mission of his agency.

One of Peck's chief critics, Rep. Timothy E. Wirth (D-Colo.), chairman of the House telecommunications, consumer protection and finance subcommittee, said yesterday, "Ray Peck systematically undermined 15 years of auto safety."

For his part, Peck said yesterday that his administration put into place programs and plans that are "a watershed in the history of protecting health and safety." Under his guidance, NHTSA was able "to bring the number killed each year on our nation's highways to its lowest level in decades, and the rate of such fatalities to the lowest level in history." The regulatory changes he made were justified on both safety and efficiency grounds, he repeatedly argued. And his supporters noted that the changes he made were high on President Reagan's list of regulatory relief for business.

Recently, however, Peck came under fire from the opposite direction, accused of trying to counter an anti-safety image by getting tough on the car companies. Peck has denied that charge, too. But his critics cite the test-film incident in support of their claim.

Simulating accidents to determine possible consequences is a legitimate testing procedure.

But officials at the Department of Transportation, which has jurisdiction over NHTSA, were upset by Peck's failure to identify the filmed test as a simulation. At the urging of his superiors, Peck subsequently called a news conference, at which his spokesman, Richard Burdette, admitted that the test was staged.

But a ranking administration official yesterday said Peck was not asked to leave his job. "Nor was he encouraged to stay," said the official, who added that "no single incident" contributed to Peck's decision to resign.

"That particular individual had difficulties in his relationship with his superiors the entire time that he served," said the administration official, speaking of Peck. "When the Transportation secretaries changed, his problems did not change."

Peck, nominated by President Reagan and confirmed by the Senate, assumed his NHTSA post in April 1981. He first served under Secretary of Transportation Drew Lewis, who left the administration earlier this year to become president of Warner Amex Cable Communications. Lewis was replaced by Elizabeth Hanford Dole, former director of the White House Office of Public Liaison.

He is expected to replaced by his deputy, Diane K. Steed, who has been working closely with Secretary Dole.

Peck yesterday thanked Dole and Lewis for their "unqualified support."

"I am grateful for the opportunity to have contributed to such an effort," said Peck, an attorney who served as president and director of regulatory affairs of the National Coal Association before joining the Reagan administration.

Some of Peck's closest friends said yesterday that he is not bitter in departure. "Can't a man quit a job in peace?" one asked.

However, those same friends say Peck was under pressure from his wife, Debby, to quit his federal job. "She did not like all of the negative publicity. She didn't like living in a fishbowl," a friend said.

Peck himself reportedly told friends, "I'll miss the excitement of it," referrring to federal service. "But I won't miss the intense aggravation of it. Most jobs have psychic income. This job has psychic loss."