A divided federal appeals court in California ruled yesterday that mandatory drug and alcohol testing for railroad workers involved in accidents violates the constitutional protection against unreasonable search and seizure.

In a 2-to-1 decision, the panel said the rules, which took effect in February 1987 and cover 200,000 railroad workers, are unconstitutional because they do not require any "particularized suspicion" that the worker is intoxicated or on drugs.

"Accidents, incidents or rule violations, by themselves, do not create reasonable grounds for suspecting that tests will demonstrate alcohol or drug impairment in any one railroad employee, much less an entire train crew," Judge Thomas Tang wrote in an opinion joined by Judge Harry Pregerson.

In a vehement dissent, Judge Arthur L. Alarcon argued that the regulations should be upheld as a reasonable effort to ensure public safety. "As recent history attests, locomotives in the hands of drug- or alcohol-impaired employees are the substantial equivalents of time bombs endangering the lives of thousands," he said.

All three judges were appointed to the 9th U.S. Circuit Court of Appeals by President Jimmy Carter.

If sustained, the decision would threaten the Reagan administration's plan to institute random testing for federal workers in sensitive positions. Some federal employees, including military personnel and Transportation Department employees, are already subject to urine testing to detect drug use.

Justice Department spokesman Patrick S. Korten dismissed the opinion as "just one of those bizarre decisions from Lotus Land," and said it was "completely at odds" with other appeals court decisions. "The chances it would survive on appeal are slim," Korten said.

Federal appeals courts have upheld random testing of jockeys and prison employees, mandatory testing of bus drivers after accidents, and mandatory testing of Customs Service employees transferred or promoted to certain jobs.

The National Treasury Employees Union has asked the Supreme Court, which has not yet ruled on the constitutionality of drug testing, to review the Customs Service decision.

Transportation Secretary James H. Burnley IV said the decision will be appealed and expressed confidence that the policy will be upheld.

Federal Railroad Administrator John H. Riley said the decision, if sustained, "will effectively end drug testing in the railroad industry." He said the "particularized suspicion" demanded by the court "is rarely available."

Riley said he is not certain whether, under the decision, the Federal Railroad Administration would have been permitted to test Ricky Gates, the Conrail engineer found by the National Transportation Safety Board to be impaired by marijuana in the Amtrak-Conrail collision at Chase, Md., last year that killed 16 people.

One or more crew members tested positive in 37 of 179 railroad accidents in which crew members were tested last year, Riley said.

Yesterday's ruling came in a challenge by all railroad workers' unions to the FRA regulations requiring that all members of a train crew submit to blood and urine tests after major accidents and fatal incidents. The regulations also permit breath and urine tests when employees are involved in less serious accidents or other incidents or when they violate a railroad operating rule.

A lower court found that the regulations did not violate the 4th Amendment prohibition against unreasonable search and seizure.

In reversing that decision, Tang said blood, urine and breath tests constitute searches under the 4th Amendment and that there must be a "particularized suspicion" of drug or alcohol use to justify such an intrusion on the worker's privacy.

William Hausleiter, spokesman for the Brotherhood of Locomotive Engineers, called the drug-testing rules "a nightmare that perhaps will go away."

"I recognize the need for sane drug and alcohol policing in the industry, and I recognize our responsibility to the public," he said. "However, I have seen the devastation that it causes in the morale and self-esteem of the worker who for some reason is called upon and is held out of work after something happens who is in no way doing drugs."

Lawrence Mann, the workers' lawyer, said the workers won "a much stronger decision than we would be prepared to collectively bargain." He said the unions are not opposed to "the concept of testing" but want to make certain that adequate safeguards are built into the regulations.