A Polish court legally registered an independent trade union for private farmers today, making it the first organization of its kind in the communist world.

The decision was greeted with loud cheers by a jubilant crowd of several thousand farmers who had gathered outside the Warsaw courtroom.The farmers' leader, 23-year-old Jan Kulaj, said that forming the rural branch of the independent Solidarity trade union marked a victory after a bitter seven-month struggle with Poland's Communist authorities.

After the court's verdict was announced, Kulaj promised that recognition of the new union will help Poland overcome its grave food crisis by restoring morale in the countryside. He was then carried shoulder-high by his supporters at the start of a procession through Warsaw.

The formal legalization of Rural Solidarity, as the union is popularly called, had been expected following an agreement last month between the government and striking farmers in the northern town of Bydgoszcz. It nevertheless marks yet another step in the process of reform that is setting Poland apart from its hard-line communist neighbors.

It also sets the seal on Kulaj's own emergence as a popular leader second only to Solidarity's president, Lech Walesa.A stout and hitherto taciturn famer from southern Poland, Kulaj is rapidly picking up some of Walesa's expansive gestures that so delight the crowds.

He knelt down today to kiss the cross, led the farmers in a throaty rendering of the national anthem and donned an elaborately embroidered folk hat. He described Rural Solidarity's registratin as the first legal act to benefit private farmers in 36 years of communist rule in Poland.

"This represents not merely the will of farmers, but also of the nation," he told his supporters, many of whom were dressed in the national costume. "It is the will of those who shed their blood in previous years so that we can speak the truth today."

In contrast to the rest of the Soviet Bl0c, Poland has tolerated private farmers since 1956 when a nationalist-inclined communist leader, Wladyslaw Gomulka, reversed an unpopular collectivization program. But the farmers complained of discrimination by the state in the distribution of scarce agricultural resources such as fertilizers and tractors.

In an emotional speech to the court, Kulaj recalled the strong opposition to Rural Solidarity's registration originally voiced by the Communist Party and its sister organization, the United Peasants' Party. Last week the Peasants' Party leader, Stanislaw Gucwa, was dismissed from his job and replaced by Stefan Ignar, 73, a former deputy prime minister believed to be more sympathetic to the grievances of private farmers.

Kulaj described previous rulings by the court against Rural Solidarity's registration as politically inspired, but added that the court now had an opportunity to act as an independent institution.

"We peasants do not want political power, but we do want to be able to control the authorities. The government must play the role of the servant of the nation," he said.

His remarks were relayed by loudspeaker to farmers waiting outside. Many carried religious banners and portraits of the pope.Several wore the latest Solidarity T-shirt that bears the words "antisocialist element" -- a frequent target of Communist Party politicians. Some banners praised the prime minister, Gen. Wojciech Jaruzelski, who is widely believed to have argued in favor of Rural Solidarity's legalization.

Union officials estimated that between two-thirds and three-quarters of Poland's 3.5 million private farmers already belong to Rural Solidarity. They predicted the percentage will rise now that the union has been formally legalized.