When William H. Webster arrived in Washington nine years ago to take over the FBI, the bureau was in turmoil.

Director L. Patrick Gray III and two other top officials, W. Mark Felt and Edward Miller, were about to be indicted for "black bag" jobs in which FBI agents had broken into the homes of friends and relatives of antiwar protesters. Congress was angry. House and Senate committees were probing FBI activities.

Morale was at a low point in the agency's history. Average citizens seemed to have lost much of their faith in the Federal Bureau of Investigation and were reluctant to volunteer information or assistance to agents.

"Those were terrible days," says former attorney general Griffin Bell, who persuaded Webster to give up his Missouri farm and his federal appellate judgeship to take the FBI directorship.

Bell supervised the investigations of Gray, Felt and Miller. And, he said, "That was one reason I was trying to find someone like Webster. We wanted rules established to make sure everything at the FBI was done legally. Webster did that."

U.S. District Court Judge William S. Sessions, who was nominated by President Reagan July 24 to succeed Webster, is expected to be approved by the Senate Judiciary Committee next week and easily confirmed by the Senate.

When Sessions moves from his Texas courthouse to Webster's old office in the massive J. Edgar Hoover Building, across Pennsylvania Avenue from the Justice Department, he will be taking over a very different agency. In his nine years as director, Webster turned the bureau around. He changed many of the people, the priorities, even the spirit of the FBI.

Despite the progress, the FBI has its share of problems. During Webster's tenure, Richard Miller became the first FBI agent arrested and convicted for espionage -- after FBI employes had complained repeatedly about his attitude and performance.Female Agent Slain by Other Agents

In 1985 Robin Ahrens became the first female agent killed in the line of duty -- after she was mistakenly shot by fellow agents as they tried to arrest a robbery suspect at a Phoenix apartment complex. One agent was fired, another resigned and three were disciplined as a result of the incident.

But Rep. Don Edwards (D-Calif.), chairman of a House Judiciary subcommittee that has conducted frequent oversight hearings into FBI operations, said that although there will always be problems, Webster "has made the FBI generally into a law-abiding agency."

Perhaps most important for the bureau, Webster used his reputation for integrity -- won during a long career as a lawyer, U.S. attorney, federal district court judge and U.S. appellate court judge -- to help restore public respect for the agency.

In a symbolic move, shortly after Webster took the job, he moved the bust of long-time director J. Edgar Hoover, known for maintaining secret files on millions of Americans, out of his office and relegated it to the public tour route.

He has also made the bureau more accountable to Congress. According to Edwards, Webster would "return a phone call in five to 10 minutes and he immediately looked into whatever the problem was." In his appearances before congressional committees, he unswervingly defended the agency's use of aggressive and sometimes controversial law enforcement methods, routinely taking the heat himself, rather than passing it along to subordinates.

Longtime agents say that morale at the bureau has never been higher.

"One thing he brought to the bureau was a career steeped in due process and the administration of justice . . . devotion to the niceties of the law. That set the tone for his approach to training agents, to the review process . . . to accountability," said former attorney general Benjamin Civiletti, who served with Webster. "That value system was a great influence on raising the sights of the day-in, day-out activities of agents in the field."

John Otto, a 23-year FBI veteran who has been acting director since Webster moved in May to his new job as director of the Central Intelligence Agency, said Webster also restored the bureau's confidence in itself.

"Morale was his greatest legacy. He returned the FBI to where it was before and then exceeded it . . . ," Otto said, adding that the restoration of "public trust sure feels good. We have to have that to get the job done."

Another big change under Webster is that the FBI is now more a reflection of American society.

When Webster took over, the bureau was still basically made up of white men. (Its first female agent was hired in 1972.) Today, the FBI is closer to the mainstream. During the Webster years, the number of female agents increased by a factor of almost eight: from 94 in 1978 to 733 on May 31. The number of black agents increased from 144 to 379, and the number of Hispanic agents from 155 to 373. There are a total of 9,200 agents.

Complaints persist that the bureau has not gone far enough, that women and minority agents are not always treated as equals. But Edwards, who served briefly as an FBI agent in the early 1940s after finishing law school, thinks that the change in hiring policies has made a dramatic difference. "They're not the ideologues of the right they used to be . . . afraid of liberals, homosexuals," he said. "It's a much healthier place now."

The FBI's priorities also have shifted dramatically. The bureau no longer responds to every bank robbery in the United States. It no longer spends a major portion of its resources investigating stolen-car rings, kidnaping and extortion, although it still handles some of those cases.

Today's priorities are much more sophisticated: terrorism, foreign counterintelligence, organized crime, drug trafficking and public corruption.Lauded for Preventing Terrorism

Edwards and others on Capitol Hill have praised Webster for his work on preventing terrorism while protecting individual freedoms. At a time when the United States is a prime target of terrorists in the Middle East and Europe, the number of cases here has steadily declined.

"He's done a good job, kept it low key and has not overreacted," Edwards said. "They have more in Paris in a week than we have in a year. There are many reasons for that, but I really have to hand it to Webster. He's kept a very cool head, and he's not panicked at any time."

Another Webster initiative has been to go after official corruption in big cities -- investigations that are often controversial. For example, in the District of Columbia, where the FBI and U.S. attorney's office are investigating corruption in city government, Mayor Marion Barry has accused the government of trying to drive him from office for racist reasons. But Webster has pledged to continue investigations in several large cities, whatever the race of the targets.

He also has moved the FBI into a major new area of crime fighting: the sting.

The most famous was "Abscam" in 1979, in which several members of Congress were captured on videotape accepting bribes. The investigation led to cries of entrapment from civil libertarians. But Webster defended his agents in hours of hearings on Capitol Hill. The defendants were found guilty and their convictions upheld.

Bell, who was attorney general when Abscam started, said he was concerned about FBI efforts to implicate Sen. Larry Pressler (R-S.D.), who appeared on the videotapes but accepted no bribe. Pressler was never charged in the case.

"Pressler shouldn't have been called in. They didn't even suspect he committed a crime. But they offered him a trap. I wouldn't like that, and neither would you," Bell said.

Because of the controversy that surrounded Abscam, Bell said, "I suspect that would never happen again. They won't call anybody in unless there's a reasonable suspicion."

Otto says one of Webster's strengths has been to "focus on the future," and that is reflected in the agency's priorities.

Instead of keeping information in file drawers or in agents' heads, as the bureau did in the old days, giant computers track cases and criminals, a practice that often worries civil libertarians like Edwards. Another computer system allows FBI offices throughout the country to tap into the latest crime files.

The FBI lab, always a strength of the bureau, is now able to enhance fingerprints -- even those more than a quarter-century old -- with lasers. It can break down blood types into many more than the usual varieties. And the lab can take a paint chip from a crime scene and analyze it to determine the make and year of car that left the chip.

Another innovation under Webster has been the psychological profiling unit, located at the FBI training center in Quantico, Va., which helps agents track serial killers, rapists, child molesters and arsonists.

Despite such progress, many people familiar with FBI operations say there will always be problems.

A major embarrassment for Webster was the 1984 arrest and subsequent conviction of Miller, a long-time FBI agent who had engaged in a love affair with and provided classified information to Soviet emigre Svetlana Ogorodnikova.

Then, in 1985, Edward Lee Howard, a former CIA officer accused of providing secrets to the Soviets, eluded an FBI surveillance team at his house in New Mexico and fled to the Soviet Union, where he was given asylum. The congressional intelligence committees, with whom Webster and Sessions will be working, have been highly critical of the CIA and FBI handling of the Howard case.Embarrassed by Informant's Testimony

The bureau was also embarrassed by congressional testimony this year by former informant Frank Varelli that he had been hired to infiltrate and burglarize the Texas office of a group opposed to U.S. policies in Central America.

Although Varelli's credibility is very much in doubt, the incident doesn't help the bureau's image. Edwards said the FBI should have known better than to deal with someone like Varelli. "Anyone could tell he wasn't giving them straight dope. He was a flake in many ways," Edwards said.

Meanwhile, at the FBI, agents generally say they're pleased with the choice of Sessions, the tough, soft-spoken Texas judge who is known for having presided over the trials of the killers of Judge John H. Wood, the first federal judge murdered in this country in more than a century.

According to Otto, before Webster left the bureau, he sat down with his top managers and drew up a three-year plan of FBI priorities, including most of the current priorities, with computer crime added to the list.

"We don't want to lose our momentum. We don't want something to come along to take us off this course," said Otto, adding that he has tried hard to keep the bureau on the course Webster kept while waiting for a new director.

Many people at the FBI said privately during the long search for a replacement for Webster that they were concerned about the possibility of a political selection for the 10-year director's term that, according to one agent, "could plunge the bureau back into the Hoover days." Several said they would like for the Reagan administration to "clone" Webster.

Bell, who got to know Sessions when Bell was on the 5th U.S. Circuit Court of Appeals, said Webster and Sessions are very much alike. "It will be good for the bureau to have these two men back-to-back," he said.