MOSCOW (AP) _ Former Soviet Prime Minister Nikolai Ryzhkov today accused former President Mikhail Gorbachev of betraying the Communist Party when it needed him most, after the failed 1991 coup.

Ryzhkov was testifying before the Russian Constitutional Court, where pro- Communist legislators are challenging the legality of President Boris Yeltsin's ban on the party and confiscation of its property.

The court renewed its order that Gorbachev appear as a witness, calling his refusal to do so ''unbecoming.'' It warned on Wednesday he could forcibly be brought to court.

Ryzhkov told the court that Gorbachev ''became such a prominent person internationally'' only by virtue of his position as general secretary of the ruling Soviet Communist Party.

''I don't understand how he can do what he is doing now,'' he said.

Gorbachev resigned as general secretary of the party in the days after the attempted takeover by Communist Party, military and KGB hard-liners. He stepped down as president on Dec. 25, 1991.

Gorbachev refuses to testify because he says it would worsen the political situation in the country.

During a break in the trial, Ryzhkov accused Gorbachev of betraying the party when it needed him most, after the coup.

''The party made him what he was,'' he said. ''It was immoral to abandon it'' after the failed coup, he said.

''And it is difficult to explain and excuse his attempts to evade appearing in this trial now,' said Ryzhkov, who was appointed prime minister shortly after Gorbachev came to power in 1985 and held the job until 1990.

Ryzhkov maintained the Communist Party was trying to reform itself. He blamed Gorbachev's ''poor organizational qualities'' for undermining that process.