U.S. District Court Judge Alcee L. Hastings went on trial today on bribery and conspiracy charges, the first sitting federal judge to be tried for a crime he is accused of committing while on the federal bench, the Justice Department said.

Hastings accused the government of racism in bringing charges against him as a result of the same FBI sting that led to the March 29, 1982, conviction of Washington lawyer William A. Borders Jr. Borders was found guilty of conspiring to arrange a bribe from two brothers convicted in Hastings' court of racketeering and fraud.

The Miami trial, expected to last three weeks, has been surrounded by accusations from Hastings' supporters that he is the victim of persecution by Reagan administration officials upset at his rulings on Haitian refugees.

Hastings, 46, is the first black judge appointed to the federal bench in Florida, named in 1979 by President Carter. Hastings made a number of rulings in 1981 against Reagan administration attempts to halt illegal immigrants from Haiti, scolding officials for subjecting Haitians to "a human shell game" and forcing immigration agents to allow lawyers to aid the immigrants at deportation hearings.

"He was very strong against the government for clubbing the Haitians," said the Rev. Gerard Jean-Juste, a Haitian priest and activist who has picketed the court to protest Hastings' trial. "They had to find a way to stop Judge Hastings."

Robert Richter, the Justice Department prosecutor, warned jurors that the case will be neither simple nor pleasant. It involves a number of taped conversations and telephone calls that, pieced together in a complicated puzzle, show that Hastings was part of the scheme to sell judicial favors, he contended.

Hastings has refused to resign since his indictment in December, 1981, although he has not been hearing cases.

Richter argued that Hastings conspired with Borders, acting as middleman, to restore $1.2 million in government-seized money and property to Frank and Thomas Romano and reconsider their three-year sentences in return for a $150,000 bribe. Hastings had ordered the property forfeited May 4, 1981, after the Romano brothers' conviction on 21 racketeering and fraud counts.

Richter and Judge Edward T. Gignoux reminded jurors that Borders' earlier conviction should remain outside their consideration. But lawyer Patricia Williams, a friend of Hastings who is defending him, contended in her opening argument that Hastings was not part of the evidence that convicted Borders, which included tapes from a wired FBI agent posing as Frank Romano.

She described Borders as "an influence peddler" seeking to trade on Hastings' name without the judge's knowledge or consent.

A tapped telephone conversation between Hastings and Borders that is a key to the government case contained nothing more than a promise from Hastings to mail some letters to authorities in Columbia, S.C., seeking favorable consideration in a mutual friend's legal difficulties, she said. Richter had portrayed the same conversation as a promise by Hastings to hand down an order restoring the Romano brothers' possessions in return for a bribe.

"All of that has a very simple, innocent explanation," Williams said. "And why don't you bear with me and let me tell you what it is?

"If the judge were involved, there's no way, I'm here to tell you," that he would not have understood it was an FBI agent posing as Frank Romano, since he saw Romano almost daily for a month during the brothers' trial, she said.