Long-simmering discontent in the black community here about alleged brutality by New York City police erupted in Harlem today as about 1,000 blacks gathered at a congressional hearing to investigate the issue.

The House Judiciary subcommittee hearing was canceled abruptly after members of the audience began shouting angrily that the more than 400 people lined up outside could not enter the crowded room to be heard.

The disruption began when a woman burst into the second-floor hearing room just as Mayor Edward I. Koch was about to testify. Waving her arms in front of television cameras, she cried, "Eight bullets. Eight bullets. You killed my son." Then she disappeared into the crowd.

Rep. Charles B. Rangel (D-N.Y.), who represents Harlem, said that the meeting at the Harlem state office building was canceled for "safety" reasons.

The inquiry into alleged police brutality has roused a political storm here recently, with Koch saying in a letter to Judiciary Committee Chairman Peter W. Rodino Jr. (D-N.J.) that the committee is being used "by those political leaders in New York City who have decided that they will seek this vehicle to enhance their political objective, which is to secure the mayoralty for themselves in 1985."

"I have no objection to Congressman Charlie Rangel, Congressman Major R. Owens D-N.Y. or anyone else running for mayor," Koch continued. "But . . . they should not take actions which might place the city or other communities in jeopardy."

New York blacks are eying with envy the success of black politicians elsewhere, particularly in the Chicago and Philadelphia mayoral elections.

Rangel, senior member of the state's congressional delegation, said today that he is "of course" considering running for mayor here. Koch, he added, "has written off blacks in the city of New York the same way Ronald Reagan has written them off nationally."

Koch, widely criticized for failing to appoint more blacks to high city posts, was booed as he walked into the hearing room today. He told reporters at a news conference later, "Our police department has a very good relationship with the community, notwithstanding the occasional rotten apple . . . . There is no systematic police brutality."

The hearing was called by Rep. John Conyers Jr. (D-Mich.), chairman of the criminal justice subcommittee, after a meeting in Washington last month with black ministers and community leaders.

One of those who attended last month and today was C. Vernon Mason, an attorney for plaintiffs in several cases alleging police brutality. He said that the Black United Front has compiled 374 complaints of alleged racial abuse by police here in the last two years.

The level of anger was reflected in that even after Conyers, Rangel, Koch and other officials left the hearing black leaders decided to hold an impromptu "people's tribunal" for the more than 400 people crowded into the steamy room.

For more than three hours, blacks of all ages from Harlem, Brooklyn, the Bronx and Queens detailed alleged beatings and verbal abuse by police.

Among those testifying was the Rev. Lee Johnson, whose case originally touched off demands for the congressional inquiry. He said that he was beaten last April by two white police officers who stopped his car in front of a Harlem restaurant and asked to see his driver's license.

The officers have denied the charge and said that Johnson was driving without a front license plate, threatened them and resisted arrest.

Leona Early, tears streaming down her face, testified that she had a nervous breakdown and a stroke after being beaten by a police officer in 1972. She said that her complaint was dismissed this month by the Civilian Complaint Review Board.

Police Commissioner Robert McGuire, in a prepared statement, noted "a disturbing overall increase . . . in complaints" against officers last year, a drop in allegations involving use of force and an increase in allegations of discourtesy or racial or offensive remarks.

He said that one-third of the force's 23,000 officers have been on the job fewer than four years and that officers have been cracking down on minor crimes sometimes ignored previously.