Prince George's County officials announced yesterday that they would use a $9 million budget surplus discovered this week to pay for the first year of a magnet school program aimed at desegregation.

The announcement ended widespread concern over how the ambitious magnet plan, launched last month, would be funded. The problem of money became critical Tuesday with the news that the county's application for a $4 million federal grant for the magnet plan had been rejected.

"I'm delighted," said Board of Education Chairman Angelo Castelli of the surplus. "Now we can go about the business of education and really show some results without worrying about where the money is coming from."

School officials had already spent $4 million for the program, which they hope will end the county's 13-year-old desegregation lawsuit, on the assumption they would be repaid by county or state funds.

County Executive Parris Glendening announced that the preliminary results of a yearly audit released Tuesday revealed a total surplus of $18 million in the fiscal year that ended last June 30, about half of which had been expected and appropriated.

Glendening said that county officials had decided that the remainder, one of the largest unexpected revenue funds in recent years, would be used for the magnet schools.

"The most immediate priority is the funding of this magnet program," he said, calling it "one of the most positive developments in Prince George's County in recent years."

While the surplus solves the problem of funding the schools this year, the county must still find $12 million for each of the next four years of the program.

Glendening and several state legislators said yesterday they were confident the Maryland General Assembly will approve funds.

The surplus, discovered by the private accounting firm that conducts the county's regular audit, was the result of tighter management and unexpected revenue from a number of sources, Glendening said.

There was additional revenue from the county's transfer and property taxes, for example, and money had been saved by not filling some vacant staff positions, Glendening said.

School officials were pressed to come up with funding for the program soon under a legal agreement with the county branch of the NAACP, the plaintiff in the desegregation lawsuit.

That understanding stipulated that the school board would take "appropriate legal action," if necessary, to force the county or state to fund the magnet program.

John Rosser, a member of the NAACP and a plaintiff in the lawsuit, greeted Glendening's announcement with a cautionary note. "I feel like it's just first base . . . we're not home yet," Rosser said. However, he said the funding this year would remove for now the threat of additional legal action.

The magnet plan, approved for a one-year period by the federal judge overseeing the lawsuit, is based on 12 magnet schools designed to attract mainly white children into predominantly black schools. The program also funnels additional money and staff to 10 predominantly black schools that officials say cannot be desegregated because of their long distance from white schools.

Glendening said his staff was more than usually conservative in drawing up the budget in hopes that a surplus this year could offset the loss of $10.8 million in federal revenue-sharing funds next year.

Instead, county officials decided to earmark the surplus for schools.

The lost revenue sharing and the $12 million required for the magnet schools next year leaves an expected shortfall of $22.8 million for fiscal 1987, Glendening said.