William J. Whalen was fired yesterday as director of the National Park Service, ending his stormy three-year effort to reconcile parkland purity with an increasingly motorized clientele.

Whalen, 40, had been under conflicting pressures from pack concession owners who wanted easier access to growing crowds and from environmentalists who feared he was sacrificing natural areas to floods of automobiles. House Interior Committee Chairman Morris K. Udall (D-Ariz.) called for Whalen's dismissal last January.

Whalen was surprised to be fired when he arrived for work yesterday morning. "I was as shocked as I could be," he said in an interview. "I feel very badly. I wish it hadn't happened."

Interior Secretary Cecil D. Andrus said in a statement that he removed Whalen "because I believed it best for the service, for the department and for Mr. Whalen's health." Whalen checked into a San Francisco hospital for three weeks last month, suffering from what a department spokesman described then as exhaustion.

However, Whalen said yesterday that he had no health worries at present and had taken the leave "to resolve some personal problems." He added that he did not understand the reasons for his dismissal since Andrus had never criticized his job performance.

"He just said that in order to bolster morale he needed to put new leadership in, and that meant I would have to go," Whalen said.

A career Park Service employe before his appointment as director in 1977, Whalen had accelerated efforts to change agency operations to cope with a tide of 268 million visitors in the system's 37 parks.

Focusing on Yosemite National Park in California, which with 2.6 million visitors last year often resembled an urban traffic jam, Whalen first cross swords with concessionaires over his plan to move most of the buildings they use to the park perimeter.

At an emotional meeting last October, he told them he resented their attempt to lobby against him in Washington and would beat them with a media campaign if necessary.

Udall, in a January letter to Andrus, said he was "outraged" by Whalen's "extremely arrogant . . . totally unwarranted and peculiarly antibusiness" remarks. He called for Whalen's dismissal on grounds of "persistent discourtesy to the public," but Andrus defended Whalen in a response.

However, Whalen apparently pleased no one with his final December proposal for Yosemite, which called for private funding for concessionaire housing outside the park. The $100 million effort to remove several hundred buildings was condemned by the Wilderness Society as "a film-flam" and "a disturbing step backward" in failing to try to reduce traffic further.

But Wilderness Society executive director William Turnage said yesterday that the Yosemite plan "was not really a reason to fire" Whalen since it was "at least a step in the right direction." Instead, he suggested, Whalen "was in over his head" in the director's post.

"He was very rude and inappropriate to the concessionaires, but he didn't really try to change policy toward them in any dramatic way," Turnage said.

Udall praised Andrus' action as "a victory for the little guy."

As a career civil servant, Whalen has the option of remaining in the National Park Service in some other job. He said yesterday he will clean out his desk this weekend and then take some time off to consider his future.