BUFFALO, N.Y. (AP) _ State Assemblyman William Hoyt, who finished third in the city's Democratic mayoral primary, said Friday he was dropping out of the race and endorsing Wilbur Trammell in the November election.

''Clearly, there is only room for two candidates in this race,'' Hoyt said. ''Therefore, for the good of our community, I have decided to set aside my own ambitions and give Judge Trammell that one-on-one opportunity to beat Mayor (James) Griffin.''

Griffin won the primary with 41 percent of the vote, compared to Trammell's 36 percent and Hoyt's 23 percent.

Trammell, who is trying to become the city's first black mayor, intends to challenge Griffin on an independent line.

With his victory, Griffin secured the Democratic line. He already had Republican, Conservative and Right-to-Life endorsements and is favored to win re-election to an unprecedented fourth four-year term.

Hoyt, who was the endorsed candidate of the local Democratic party, had said he was prepared to continue the race even after losing the primary. Hoyt would have appeared on the ballot under the Liberal Party line.