Roy Lee Williams, president of the International Brotherhood of Teamsters, Chauffeurs, Warehousemen and Helpers of America, cut a deal with a federal judge yesterday, agreeing to surrender his powerful office in order to keep out of jail.

The sealing of his fate after a bribery conviction intensified a secret struggle among potential successors to the leadership of the 1.6-million-member labor union, the nation's largest, most feared and most scandal-ridden.

From his hospital bed in Kansas City, where he reportedly is suffering from severe emphysema, Williams, 68, agreed by telephone to resign "unconditionally" from all his union positions by 5 p.m. next Wednesday.

In return, U.S. District Court Judge Prentice H. Marshall, presiding in a Chicago courtroom, said he would stay a provisional 55-year sentence and allow Williams to remain free on bail during his appeals.

Justice Department officials had sought an immediate resignation, but Williams' lawyer, Raymond Larroca, persuaded them to allow Williams to step down at a Teamsters executive board meeting next Tuesday in Scottsdale, Ariz. Williams wants "to say goodbye to his friends and leave with a minimum of dignity" after being a union member for 45 years, Larroca said.

The wording of the affidavit signed by Williams bars the union leader from any participation in Teamsters' affairs between the time he signed it and the hour of his resignation.

However, there was speculation yesterday that he might take the opportunity at Tuesday's farewell to try to influence the choice of his successor.

The names most prominently mentioned as candidates for the prize post, which has provided Williams with $780,000 a year including expenses, are union Vice President Jackie Presser, leader of the Ohio Teamsters, California-based M.E. (Andy) Anderson, Florida-based Joseph Morgan and Chicagoans Ray Schoessling and Don Peters.

Cleveland-based Presser is the most controversial on the list. His supporters have been putting out word that they have formed an alliance with Anderson--reportedly one of the strongest contenders--and now have the votes to win the presidency, according to one source familiar with the union.

However, a number of sources said Presser is disliked by many within the union, including Williams, and may be considered "too hot" for the top post.

Presser's selection for the Reagan administration transition team in 1981, in return for his strong support of the presidential candidate, generated a burst of negative publicity about his alleged ties to organ- ized crime. Currently his name is being linked by the Cleveland media to a continuing federal investigation into mob-related activities.

Ken Paff of the dissident Teamsters for Union Democracy, which represents about 8,000 of the union's members, said, "Presser's running hard, but he's our least favorite. There is nothing we could say that would convey how evil we think he is."

Dissident Teamsters, government sources and other sources indicated that none of those in the candidate pool is likely to drastically alter the union's basic way of doing business.

"They're all cut from the same mold," Paff said. "Most of them are millionaires, and meanwhile the union is going down the drain."

Paff's group charged Thursday that the Teamsters union had paid for the more than $535,000 in legal expenses incurred by Williams.

"Needless to say, there's a lot of interest in who's going to get it the presidency ," said one Capitol Hill source. "It will be a strong signal whether there's any chance at all to clean up the operation . . . . But it's really a matter of degrees."

The selection process for the Teamsters presidency is a tightly held one.

The union constitution provides that when William resigns Wednesday the secretary-treasurer, Schoessling, will assume office for up to 15 days. During that time he must call a meeting of the 17-member executive board, union officials said.

The executive board must elect the new president from among its own elected (not appointed) members. Officials said this provision disqualifies Walter Shea, Williams' top assistant in Washington.

The newly elected president will serve until the union's next convention, in June, 1986.

Williams, a barrel-chested, square-jawed man given to "truckers' language," became president of the Teamsters in the spring of 1981, despite the fact that he had just been indicted on the bribery charges that proved to be his downfall.

He was convicted last December of conspiring to bribe then-Sen. Howard W. Cannon (D-Nev.). (No bribery occurred.) One of his co-defendants, insurance executive Allen M. Dorfman, was shot to death gangland-style in January.

Two other Teamsters officials served time in prison: Dave Beck and the legendary Jimmy Hoffa. Both men continued to run the union from their prison cells.

Hoffa disappeared under mysterious and, authorities believe, violent circumstances in 1975.

The union, often billed as the largest in the free world, was the only major labor organization to endorse President Reagan for the White House.

First chartered in 1899, it originally was concentrated in the delivery trades: haulers of milk, construction equipment and coal. But presently, truckers and haulers make up barely a quarter of the total membership. The union's aggressive organizing methods have enabled it to expand into police and fire departments, hospitals and other fields.

Last year, Mickey and Minnie Mouse, Donald Duck, Goofy and the nearly 100 other actors and actresses at Walt Disney World in Florida signed up with the Teamsters.

In 1957 the late George Meany, then president of the AFL-CIO, kicked the union out of the labor federation for failure to rid itself of alleged "corrupt domination." Recent moves to bring the giant union back into the AFL-CIO have failed so far.