In a stunning upset for the leaders of Girard College, a judge has ruled that the school may not suspend its high school and boarding programs to improve its finances.

Orphans Court Judge Joseph D. O'Keefe said those programs were critical parts of the vision that the merchant-banker Stephen Girard outlined in his 1831 bequest that created the unusual free boarding school for poor orphans on a 43-acre site in Fairmount.

As a result, O'Keefe denied a petition by the board that oversees Girard College seeking permission to amend Stephen Girard's will to make the planned changes for the fall of 2015.

The judge issued his order and an accompanying opinion Friday, and they became public Monday when posted on the docket.

The ruling, which followed a hearing last month, was a triumph for Girard students, parents and staff and extensive alumni community who had mobilized to protest the proposed changes.

"Words can't even express how excited I am about this," said an elated Brandon Dixon, 17, a senior from Juniata Park and Girard's student body president. "All day I've been jumping around. I'm happy."

Joseph Samuel, president of the Girard College Alumni Association, said its members were "gratified" by the decision.

"Judge O'Keefe recognized the fundamental elements of Stephen Girard's vision for residential education through to graduation for whatever number of students who could be educated and housed there with available resources," said Samuel, a 1988 graduate.

He said the judge had also recognized that challenges remain. "We alumni want to work with the board and the administrators to find innovative ways to educate Girardians who live on the campus and who work to be productive. We feel very positive about this."

The judge's order shocked and dismayed the Board of Directors of City Trusts, which oversees Girard and had petitioned the court last summer to allow the change, saying it was crucial to restoring the school's finances to stability.

"We certainly appreciate the time and the attention that Judge O'Keefe devoted to this issue, but it is unfortunate that the court has chosen the path that only prolongs the financial uncertainty that now threatens the future of Girard College," said Kevin Feeley, a board spokesman.

"The reality is that if Girard continues to spend beyond its means, ultimately it will be unable to replenish the trust so that it can continue to serve children in need," said Feeley, a 1973 graduate of Girard. "The board respectfully disagrees with the court's decision."

Feeley said it was too soon to say whether the board would appeal.

At the time the board petitioned the court, it warned that unless the changes were permitted, the funds to support Girard could be depleted within 25 years and the school forced to close.

The board said it spent $42,500 per student to provide a college-preparatory education and 24-hour care five days a week for students who live on the school's 43-acre campus.

Feeley said 300 students from first through 12th grade are enrolled at Girard.

The school suspended its weekend boarding program in 2009 to cut costs. In his decision, O'Keefe pointed out that Girard had made that move without seeking the court's permission.

In its 2013 petition, the Board of Directors of City Trusts had asked the court to allow it to drop the boarding and high school programs so it could switch to an extended-day program with more rigorous academics for 425 students in first through eighth grades.

In his decision, O'Keefe said that while the board had treated the proposed changes as "administrative deviations," he disagreed.

"The design of Girard College as a boarding school, intended to provide a residence, as well as an education, to its students is reflected in the very terms of the will," he wrote.

He also said that Girard's will called for students to "remain in the college until they shall respectively arrive at between fourteen and eighteen years of age."

The judge said he sympathized with the school's financial plight but said those concerns could not override Stephen Girard's wishes. The judge also noted that school's financial picture had improved in 2013.

Over the years, the courts have approved several changes to Girard's will, which had called for establishing a school to "educate poor, white, male orphans."

It took two trips to the U.S. Supreme Court and seven months of around-the-clock picketing by civil-rights protesters before the school was integrated in 1965.

Another lawsuit nine years later led to the admission of girls. And the definition of orphans was expanded to "functional orphans" to include children from single-parent homes.