In a speech to more than 20,000 cheering blacks in Madison Square Garden tonight, Black Muslim Minister Louis Farrakhan warned politicians that they would face "a disgraceful death" if they condemn him.

Surrounded by six female bodyguards in turbans, flowing white robes and crimson epaulettes, Farrakhan preached an angry sermon for more than two hours, attacking Jews in particular, whites in general and numerous politicians, including President Reagan, New York Gov. Mario M. Cuomo and Mayor Edward I. Koch.

"The Jewish lobby has a stranglehold on the government," Farrakhan declared, saying that 246 House members and 46 senators are honorary members of the Israeli Knesset. "Whatever they Jews want, they get it, and the president himself is punking out to the Jewish lobby," he said.

Farrakhan charged that politicians and community leaders who have criticized him for anti-Semitism are "trying to discredit the power of my message . . . . Ultimately the aim is to murder me."

Noting that Koch compared him to Hitler, Farrakhan said, "The germ of murder is sown in the heart of Jews across this nation."

Farrakhan's appearance here, the final event of a cross-country speaking tour that has attracted large audiences in Los Angeles, Washington, Baltimore and other cities, set off a furor over the past week.

New York politicians, including City Clerk David Dinkins, the highest elected black official in city government, denounced Farrakhan for his past anti-Semitic remarks. Other black leaders, however, said they resented being called on to condemn him as a "litmus test" of their racial sensibility.

Koch attacked the Chicago-based Nation of Islam leader at a news conference Thursday, calling Farrakhan "a Nazi in clerical garb." Acknowledging Farrakhan's appeal for blacks' economic self-improvement, the mayor said, "It's not enough to say he's addressing an economic issue. So was Hitler. He's using an economic issue just as Hitler did -- to vent bigotry, anti-Semitism, anti-white feelings."

Farrakhan tonight, implying that Koch is a homosexual -- a charge that the mayor has denied repeatedly -- told his applauding audience that "Mr. Koch ought to be very careful because the Scripture says upon Jesus' return he will not accept certain characteristics."

As for Dinkins and other black leaders who have criticized him, Farrakhan said, "These silly Toms run out and do their masters' duty. When a leader sells out, the black people pay a price for that. We should make examples of these leaders."

Security was strict at the rally as hundreds of members of the Fruit of Islam, Farrakhan's paramilitary unit, tried to control thousands of supporters pressing against the doors. Every person who entered was frisked and searched, men and women in separate rooms. The procedures delayed Farrakhan's speech by more than two hours.

Before Farrakhan spoke, the crowd was warmed up with fiery oratory from former Black Panther leader Stokley Carmichael, Native American leader Russell Means and a representative of the Palestinian Congress of America.

Throughout his speech, Farrakhan, calling forth the ghosts of Malcolm X, Martin Luther King and other assassinated black leaders, returned repeatedly to the possibility of his own murder, associating himself with the martyrdom of Christ.

Instead of his critics likening him to evil whites, "Why didn't they compare me . . . with Jesus?" he asked. "Jesus was hated by the Jews. Farrakhan is hated by the Jews. What did they hate Jesus for? Because he exposed their wickedness and sin."

In the days before the rally, several prominent black leaders joined in the repudiation of Farrakhan, but questioned whether it was necessary.

"It's like, 'All right, folks, let's have litmus-test time,' " said Assemblyman Herman D. Farrell, who ran for mayor against Koch in the September primary.

Rep. Charles B. Rangel (D-N.Y.) told The New York Times, "I just hope that this is not coming to the point where, if blacks in South Africa have to carry a passbook to go from place to place, that black Americans have to carry their last statement refuting Farrakhan."

Blacks make up 24 percent of the city's population. Jews are estimated at 1.6 million, or 16 percent of the metropolitan area of New York, Long Island and Westchester County -- the largest concentration in the nation.