Labor Secretary Raymond J. Donovan, plagued by charges that he was tied to organized crime before taking office, resigned yesterday hours after a New York State Supreme Court judge ruled that he must stand trial on 137 counts of grand larceny and fraud.

President Reagan, who was Donovan's staunchest defender during more than four years of controversy, met with him for 10 minutes and released a one-paragraph letter accepting his resignation with "deep personal regret."

"I want you to know that you leave the Cabinet with my friendship and gratitude for the years of service you have given to this administration -- and for the tireless efforts you have made in my campaigns," Reagan said.

The White House was not surprised by Donovan's decision. Officials there said he had assured them that the case against him would be dismissed but also had indicated in general terms that he would step down if compelled to face trial.

White House spokesman Larry Speakes emphasized, however, that Donovan was not pressured to resign.

Speakes said that Donovan informed White House chief of staff Donald T. Regan of his decision about an hour before Judge John P. Collins announced he was denying motions to dismiss the charges against the secretary.

"The evidence in this case, if proved and believed, demonstrates a carefully contrived attempt to steal property," Collins said in denying the motions. "There is no justification warranting this court to dismiss the indictment in the interests of justice."

A statement issued later by the Labor Department, however, said Donovan had told the president that he remained confident that the charges against him will be found "baseless." And Donovan's lawyer, William O. Bittman, said the secretary had resigned because of uncertainty over when a trial might begin and how long it would last. Donovan has been on leave of absence since he was indicted Oct. 1, 1984.

White House officials said no one had focused on a successor. Sources at the Labor Department said names that have gone to the White House from labor-management circles include James C. Miller of the Federal Trade Commission, Kay McMurray, director of the Federal Mediation and Conciliation Service, and Rep. John N. Erlenborn (Ill.), the former ranking Republican on the House Education and Labor Committee.

W.J. Usery, who held the McMurray post during the Ford administration; Edward J. Rollins, assistant to the president for political affairs, and two retiring Republican governors, Richard L. Thornburgh of Pennsylvania and Pierre S. DuPont IV of Delaware, also are considered possibilities.

Donovan has been on leave of absence since Oct. 1, 1984, when the indictment was announced. But he has been an investigative target since Dec. 22, 1980, when he confirmed that he had been questioned in 1969 by federal agents looking into a New Jersey kickback scheme.

Donovan frequently objected that he had never been convicted of anything and protested that he was a victim of innuendo. But he was considered a political liability in the 1982 midterm campaign, where Reagan advisers shunted him away from key states, and James A. Baker III, the first-term White House chief of staff, advocated that Donovan leave the administration.

"Ray Donovan shouldn't be in here," Baker said in a January 1983 interview with a Texas newspaper. "What's he thinking about? He's got his good name now . . . . He ought to do what's right for the president."

Baker and others in the administration, even some who defended Donovan's innocence, considered him an ineffective secretary who had failed to build ties with mainstream union leaders.

However, Reagan steadfastly stood by Donovan and refused to pressure him to step down. Donovan would have been "gone from here long ago," an official said, except for the president's loyalty.

Donovan expressed his gratitude in his meeting with the president yesterday, where he also reiterated his innocence.

A Labor Department statement said Donovan told Reagan "that he was confident that he would be fully exonerated of all the baseless charges" against him but also stated "that he would not allow his personal circumstances to distract the president or the country from the administration's mission of securing America's preeminent position in the world."

Donovan's farewell letter said, "It has been the greatest privilege of my life to have served for four years in the Cabinet of the best president this country has ever elected."

But Judge Collins' 27-page ruling yesterday represented a heavy blow for Donovan, whose representatives earlier had assured White House officials the case was too flimsy to go to trial. Donovan was so optimistic about the outcome, Labor Department sources said, that his subordinates were soliciting funds for a welcome-home party when he returned.

Collins, however, after reviewing relevant grand jury proceedings, studying exhibits and listening to long-secret FBI tape recordings, said he was satisifed that the case was strong enough to be tried on its merits.

Donovan, nine other men, and the two companies they headed were indicted by a Bronx County grand jury last October on charges of conspiring to defraud the New York City Transit Authority of $7.4 million in connection with a $186 million subway project in midtown Manhattan. The contract was awarded in 1978 to a joint venture headed by the Schiavone Construction Co. of Secaucus, N.J., where Donovan was executive vice president and of which he still holds 40 percent.

At a news conference yesterday before Donovan resigned, Bronx District Attorney Mario Merola hailed the court ruling as "a vindication of the fact that nobody's above the law."

He said he hoped it also would bring an end to the name calling and "personal attacks" that have been directed at him and his office over the past six months.

"I just hope we get away from the personalities and start dealing with the meat," Merola said. "The judge has indicated that all the defendants in this case will have to stand trial . . . . We have been ready for trial since the day we filed the indictment."

In this case, Merola added, "things have been improving. We've got additional information and evidence."

Holding that the principal charge, grand larceny, was aptly brought, Judge Collins said that "in this case, the transit authority bargained for the building of a tunnel and some more. That 'some more' was that the tunnel was to be constructed using some minority business enterprise. The federal government was handing over 80 percent of the construction funds. It reasoned that requiring the use of some minority business enterprise was valuable to minorities and to the good of the nation as a whole . . . . The transit authority, in order to obtain the federal money, agreed to comply with the requirement."

Accordingly, the judge said, the transit authority required its contractors to "promise" that 10 percent of the dollar value of the work be subcontracted to minority business enterprises (MBE) and it was on the basis of that kind of a contract that Schiavone Construction received its money.

"The people contend that from the outset, the Schiavone Co. never intended to fulfill that promise," Collins said. He said prosecutors for Bronx District Attorney Merola not only presented evidence to the grand jury to support that contention, but also to show that the principal MBE on the job, Jopel Contracting and Trucking Corp. of the Bronx, "was not a legitimate minority business enterprise."

Noting that the prosecution might argue that Schiavone and Jopel had "a sweetheart arrangement," Judge Collins said, "the people allege that the Schiavone Co. wrongfully obtained in excess of $7 million," money that prosecutors say "should have gone to an MBE but instead by reason of an involved scheme to defraud, . . . remained with the prime contractor."

For instance, Collins said, the Schiavone Co. bought expensive tunnel-boring machinery and ostensibly leased it to Jopel for a monthly figure, but "the evidence indicates that often Jopel employes didn't operate the machinery and had no responsibility for tunnel work. Instead Schiavone Co. personnel operated it. Jopel never received any money -- from the joint venture -- to cover the rental cost. The Schiavone Co. treated the matter as a paper entry -- a debit and a credit at the same time."

Meanwhile, the judge said, Schiavone Construction submitted quarterly reports to the transit authority that represented the paper rental costs as money actually paid to Jopel, thereby "inflating the amount of dollar value work subcontracted to an MBE" in satisfaction of the 10 percent requirement, and at the same time providing Schiavone Construction "with tax benefits."

In short, Collins ruled, "there is evidence before the grand jury that false reresentations were made concerning the legitimacy of Jopel's MBE status and the monies received by Jopel. These representations . . . were material, there is evidence that the defendants were aware of their falsity, and they were given with an intent to defraud."

The judge also denied a lengthy list of other defense motions, sometimes in clipped and caustic terms. At one point, he said Donovan's lawyers seemed to be arguing that submission to the Bronx grand jury of prior testimony by the defendants before a 1982 federal grand jury somehow entitled them to immunity in the Bronx.

"It is a novel argument," Collins said. "It is totally without legal foundation."

Collins did not address himself to the case against Donovan or other individual defendants except to state that "the evidence presented to the grand jury is sufficient to support the charges against each of the named defendants."

The judge also took note of an interest-free $200,000 loan that Schiavone Construction gave Jopel in March 1979 in so-called start-up money for equipment needs. Donovan cosigned the check. The head of Jopel, reputed mobster William P. Masselli, told special prosecutor Leon Silverman during a 1982 federal investigation that he paid a Schiavone executive, Joseph DiCarolis, a $20,000 kickback in return for the loan.

Silverman, who investigated alleged ties between Donovan and organized crime figures, concluded in September 1982 that there was "insufficent credible evidence" to warrant Donovan's indictment for any federal crime.

During the first Reagan term one of Donovan's principal defenders in the administration was Edwin Meese III, then the White House counselor and now U.S. attorney general. Officials said that Donovan was conspicuous by his absence at the ceremonial swearing-in of Meese on Thursday.

When one of those attending the ceremony inquired of a White House official about Donovan's absence, he was told, "It wouldn't be appropriate for him to be here at this time."

White House officials insisted yesterday that chief of staff Regan had not been promised in advance that Donovan would resign if the judge ruled that he had to face trial. But in conversations during the past few weeks Regan reportedly has stressed that Donovan would return to his post only if the defense motions were upheld. Regan declined comment on this yesterday.