Max Hugel, the Central Intelligence Agency's chief of clandestine operations, resigned yesterday within a few hours after he was accused in published allegations of improper or illegal stock trading practices.

He was immediately replaced by John Henry Stein, 49, a career CIA officer.

White House aides said they were prepared to recommend that President Reagan fire Hugel but his resignation preempted them. In an early morning telephone call, CIA Director William J. Casey informed White House chief of staff James A. Baker III, "Max is going to step aside."

This call concluded five days of discussions among Casey, Baker, CIA counsel Stanley Sporkin, White House counsel Fred Fielding and others about how to deal with an anticipated series of damaging allegations against Hugel based on tape recordings provided by two Wall Street stockbrokers who did business with him seven years ago. The charges were disclosed in yesterday's Washington Post.

Reagan was not informed until late Monday of the charges against Hugel, whose job as CIA deputy director for operations is one of the most sensitive in government. Baker told the president that the story was due to be published in The Post on Tuesday morning and said Reagan's response was that he was "saddened" to learn of the accusations.

The next time Reagan heard about the matter, Hugel had already quit. The news was relayed to the president at the regular morning staff meeting by Baker, White House counselor Edwin Meese III and deputy chief of staff Michael K. Deaver.

In his resignation letter to Casey, Hugel called the allegations against him "unfounded, unproven and untrue." The 56-year-old former president of a New York wholesale firm said he was leaving because "under present circumstances, I feel I can no longer effectively serve you or the agency."

Casey, in his letter, replied: "It is with deepest regret that I accept your resignation. I do, however, respect your wishes and fully understand your position. I greatly appreciate your efforts for this agency. You have deservedly earned the respect of those with whom you have worked."

Later in the day, White House spokesman David R. Gergen reiterated that the decision had been made at the CIA by Casey and Hugel and several times repeated Hugel's assertion that the charges have not been proven.

In response to a series of questions at the daily White House briefing, Gergen said that the president continued to have "great faith" in Casey's judgment and believed that he had done "a first rate job" at the CIA. At the time Hugel was appointed to his sensitive post more than two months ago, Casey's judgment in making the choice was widely questioned.

Veterans of the intelligence community, as well as some high White House aides, said they were surprised that Casey had chosen politically oriented and inexperienced outsider rather than a career man.

Following initial questions about Hugel's qualifications, Casey defended him in a long, personal letter to Reagan. Casey's main argument was that he needed someone in the sensitive post in whom he could place his absolulte trust and that Hugel, Casey's friend of 20 years, filled that prescription better than any other candidate.

There was no immediate sign that Casey's own position within the administration had been shaken. The president has trusted Casey, aides emphasized, ever since the 68-year-old former chairman of the Securityes Exchange Commission helped straighten out the tangled finances of the Regan campaign last year.

Casey was an unpopular figure with other campaign aides, and since his appointment as CIA director he has been accused of politicizing the agency. There is no evidence that this opinion is shared by Reagan, however. a

Meanwhile, a federal judge in New York has ruled that Casey knowingly misled potential investors in a now-defunct agribusiness company which he served as a board member and corporate secretary. [Details, Page A9]

Gergen said that Fielding heard the first report of Hugel's difficulties "from a third party" last Wednesday. Fielding told Baker about it. On Thursday, Gergen said, Fielding sat down with Hugel to discuss the issue.

That night, CIA counsel Sporkin, former chief SEC enforcer under Casey during the Nixon administration, began detailed questioning of Hugel.

Friday morning, Sporkin requested a meeting with Post editors and reporters. The meeting was arranged on the condition that Sporkin would bring along Hugel to confront allegations made to the paper by Thomas R. McNell and Samuel F. McNell, whose securities firm traded the stock of Brother International Corp. Hugel was president of this company from 1954 to 1975.

The McNells charged that Hugel regularly provided them with confidential inside information about his company. They said Hugel improperly funneled $131,000 into the McNell securities firm and that he helped them use the firm to improperly boost trading in Brother stock.

At a four-hour session Friday, Hugel emphatically denied these accusations, but asked for time to consult his business records.

While Hugel was doint this ove the weekend, there were conversations on what to do about the controversial spymaster at both the White House and the CIA. At some point, portions of tape recordings made by Sporkin of the interview at The Post were played for Casey.

Sources close to the investigation said that the most damaging recording was one in which Hugel complains that he's "got my bank on my ass" and urges the McNells to do anything to create additional trading activity in his company's stock.

"At least trade," the taped Hugel says. "And I'm going to blow this thing right into China if I have to."

It is not clear when the precise moment was that the administration decided to jettison Hugel. At the White House the strategy was to insist that Casey had made the appointment and that it was up to him to decide on whether Hugel would go. This had the seeming advantage of keeping the action further removed from the president.

Baker insists that the White House never had to make a decision.

He said that Casey and Hugel did it on their own and added, "This is probably more likely Max's idea than it was Casey's -- the way Casey put it to me."

Casey has refused to comment. Hugel was described as having been completely ostracized at the Langley headquarters of the CIA. People who saw him said that he was subdued in manner and that he still firmly believes that the business practices detailed on the tapes were neither illegal nor improper. He is said to believe that the moments he made demonstrated no more than the enthusiasm of an aggressive business executive.

Hugel regards his accusers as vindicative men who tried to swindle him out of an insurance settlement. Thomas McNell, reached yesterday, responded, "He's a liar, he swindled us."

Securities experts said yesterday they see little likelihood that charges will be brought against either Hugel or the McNells because the staute of limitations probably has expired.

The swift appointment of Stein in Hugel's place as the new deputy director for operations signaled a return to the familiar pattern of putting a career intelligence official in this sensitive job. The prevailing view in the White House and the intelligence community was that Stein should have been given the job in the first place.

Stein's resume reads like a central casting version of the successful CIA agent. He graduated from Yale in 1955 and held posts in Europe, Africa, Cambodia and Libya.

Former ambassador to Cambodia Emory C. Swank, who served with Stein in Phnom Penh, described Stein as "very career, doesn't make waves, very hard worker, the sort of personality the agency prefers, particularly on the operations side."

Behind the public statements of how "saddened" Reagan was by the episode, White House aides wee congratulating themselves on how quickly Hugel had left the administration. "It was done in time for the afternoon papers," said one aide.

Casey's parting letter to Hugel, his friend of 20 years, said: "I know that you will not lose your dedication to our nation's security and welfare and I wish you will in whatever you undertake in the future." Texts of the Hugel-Casey Letters

Following are the texts of Max Hugel's letter of resignation as CIA deputy director of operations to CIA Director William J. Casey, and Casey's response.

Hugel's letter:

Dear Bill:

As you know, since I was appointed deputy director of operations I have been the subject of repeated unfavorable articles in the press, the most recent one being this morning.

Theses allegations, although unfounded, unproven and untrue, have become a burden which I no longer believe is fair to impose on the administration, the agency, my family, and the splendid men and women who work with me.

Accordingly, with deepest regret and sorrow, I hereby tender my resignation effective as of the close of business today.

I want you to know how appreciative I am for the opportunity you have provided to serve my country.

However, under present circumstances, I feel I can no longer effectively serve you or the agency.

Although I am resigning, I want you to know that I am available for any future assignment in which you believe I can be of help. Sincerely, Max Hugel Casey's reply:

Dear Max,

It is with deepest regret that I accept your resignation.

I do, however, respect your wishes and fully understand your position.

I greatly appreciate your efforts for this agency. You have deservedly earned the respect of those with whom you have worked.

I know that you will not lose your dedication to our nation's security and welfare and I wish you well in whatever you undertake in the future. Yours, William J. Casey