To his students, Ahmad al-Khatib was a deputy principal at an elementary school in Gaza run by the United Nations agency for Palestinian refugees. To Hamas’s military wing, documents say, he was something else entirely: an infantryman operating out of the southern Gaza city of Khan Younis.

The military wing, known as the Qassam Brigades, kept meticulous records of its fighters, tracking the weapons they were issued and regularly evaluating everything from their fitness to their loyalty.

Mr. al-Khatib, an employee of the U.N. agency since 2013, was among them: Secret internal Hamas documents shared with The New York Times by the Israeli government say that he held the rank of squad commander, was an expert in ground combat and had been given at least a dozen weapons, including a Kalashnikov and hand grenades.

The refugee agency, known as UNRWA, operated schools across Gaza before they were shuttered in the wake of Hamas’s Oct. 7 attack on Israel and the ensuing war. The agency, which employs roughly 13,000 people, including thousands in the schools, has a duty to maintain the neutrality of its facilities in the conflict zones in which it operates, including by keeping militants off its premises and payrolls.

But interviews and an analysis of the records shared with The Times by the Israeli military and foreign ministry indicate that Mr. al-Khatib was one of at least 24 people employed by UNRWA — in 24 different schools — who were members of Hamas or Islamic Jihad, another militant group. Before the war, the agency was responsible for a total of 288 schools, housed in 200 different building compounds, in Gaza.

A majority were top administrators at the schools — principals or deputy principals — and the rest were school counselors and teachers, the documents say. Almost all of the Hamas-linked educators, according to the records, were fighters in the Qassam Brigades.

The Israeli military said it had obtained the trove of documents during its campaign in Gaza. While The Times had no way to independently authenticate the records, they bear similarities with other Hamas records that The Times has examined. Beyond that, names and identification numbers listed on the seized documents match those in a separate UNRWA database.

UNRWA officials say Israel is pursuing a campaign to discredit the agency and ultimately shut it down. The agency has long provided education, health care and other services to millions of Palestinians in Gaza, the West Bank, Lebanon, Syria and Jordan, and has turned many of its schools into shelters during the current conflict. It is difficult, U.N. officials say, to guarantee that there are no militants among the agency’s workers in Gaza, where it is one of the largest employers, and where Hamas has exercised ironclad control for nearly two decades.

The agency’s schools in Gaza have become a flashpoint in the current conflict. Close to 200 UNRWA facilities have been struck since the war began, many of them schools.

Israel claims that Hamas has used the buildings for military purposes and to hide its fighters, making them legitimate targets under international law. But the United Nations says that Israeli strikes on schools have likely violated the law by causing disproportionate harm to noncombatants.

Among the seized records are secret Hamas military plans that show that the Qassam Brigades regarded schools and other civilian facilities as “the best obstacles to protect the resistance” in the group’s asymmetric war with Israel. The documents also list two schools in particular that were to be used as redoubts where fighters could hide and stash weapons in a conflict.

The Israeli government shared the documents at The Times’s request, after Israeli officials had circulated a list of 100 UNRWA workers it alleged were militants. The Times asked for documents specifically related to school employees, who, as a sizable subset of the agency’s employees, offer a window into the evidence behind Israel’s claims.

The seized records — coupled with interviews of current and former UNRWA employees, residents and former students in Gaza — offer the most detailed evidence yet of the extent of Hamas’s presence inside UNRWA schools. In several cases, educators remained employed by UNRWA even after Israel provided written warnings that they were militants.

The group’s presence in education appears to have extended beyond Gaza’s borders: In September, Hamas announced the death of its leader in Lebanon — a school principal and a former head of UNRWA’s teachers’ union in that country.

Israel has long accused UNRWA of doing too little to prevent infiltration by Hamas. Earlier this year, Israel alleged that 18 of the agency’s workers participated in the Oct. 7 attack, and several countries that fund UNRWA suspended donations.

In October, the Israeli Parliament passed legislation aimed at shutting down UNRWA’s Gaza and West Bank operations, and it has recently briefed diplomats from countries that fund UNRWA on the documents shared with The Times.

While Israel asserts that other aid agencies could perform UNRWA’s functions, humanitarian officials worry that the abrupt transition Israel seeks could be catastrophic.

UNRWA has said it takes allegations that staff members were militants seriously. In response to the Times inquiry into the documents, UNRWA officials said that the agency had put one employee on administrative leave and that the United Nations had requested more information from Israel on about 10 others.

Philippe Lazzarini, UNRWA’s commissioner general, said the agency had struggled to get information from Israel that would allow it to act on the allegations. He added pointedly that it was “extraordinarily interesting” that the Israeli government had not chosen to share the materials with the agency itself.

But he also acknowledged that UNRWA lacked the resources to independently investigate such allegations.

“We have always been clear that we are not an intelligence or security type of organization,” Mr. Lazzarini said in an interview.

Israeli officials, for their part, said that the United Nations had tried to minimize the problem. They have expressed frustration about how the United Nations responded when Israel shared detailed intelligence earlier this year about the 18 UNRWA workers it accused of participating in Oct. 7.

“The U.N. seems intent on portraying this problem as a few bad apples, rather than acknowledging that the tree is rotten,” said Amir Weissbrod, the foreign ministry’s deputy director for international organizations.

Basem Naim, a spokesman for Hamas, declined to comment.

The Times could not reach most of the educators named in the documents because their phone numbers were not working, they did not respond to messages on social media, and it is difficult to track down people in a war zone where Israel largely bars reporters from entering.

Residents of Gaza said in interviews that the idea that Hamas had operatives in UNRWA schools was an open secret. One educator on Israel’s list of 100 was regularly seen after hours in Hamas fatigues carrying a Kalashnikov.

The documents do not indicate whether all of the 24 educators participated in active combat. But the records, along with interviews, do indicate that at least one-third of them were given the tools to do so.

Take, for instance, Mustafa al-Farra and Ayman al-Alami, who are listed as UNRWA teachers in Jabalia and Khan Younis. Multiple Qassam Brigades personnel documents seized by Israel separately list them as fighters. In addition, records bearing the military wing’s letterhead show that Mr. al-Farra was issued an AK-47, while Mr. al-Alami participated in a Hamas rocket-launching training course in 2023.

Before Oct. 7, Israel did not consider uncovering Hamas ties to UNRWA an intelligence priority. Still, intelligence analysts would occasionally uncover evidence of Hamas’s infiltration and pass it along.

In 2011, the foreign ministry alerted UNRWA that one of its educators, Naji Abu Aziz, was a Hamas operative, and urged the agency to conduct an investigation. UNRWA did launch an inquiry, but in a letter sent to the foreign ministry at the time, it said that it needed more evidence. The ministry responded that revealing such information could endanger intelligence sources.

Records since seized by the Israeli military list Mr. Abu Aziz as a member of the chemistry unit of Hamas’s military manufacturing department. Mr. Abu Aziz’s potential link with Hamas also surfaced in 2020 on a Telegram account. A seized Hamas communiqué noted the disclosure, confirmed Mr. Aziz’s membership in the chemistry unit of Hamas’s military manufacturing department and recommended that the Telegram account be hacked and shut down.

Mr. Abu Aziz is listed in the UNRWA database as the principal of the Khuza’a Prep Boys School.

In other instances, the agency did not fire Hamas operatives after tunnels were discovered under or adjacent to its schools.

In 2017, UNRWA discovered a tunnel that passed under the Maghazi Prep B Boys School in central Gaza. The agency said at the time that it had lodged a protest with Hamas over the tunnel and had moved to seal entrances.

Seized records say that the principal of the school, Khaled al-Masri, is a Hamas member who was issued an assault rifle and a handgun, and he is pictured standing in front of a Hamas banner on Facebook.

He remains on UNRWA’s staff, the agency says, but is under investigation for a social media violation.

This February, Israeli officials said, their forces conducted a raid on a tunnel shaft next to another UNRWA school, which led underneath the school to a nearly half-mile-long tunnel equipped with weapons. Seized Hamas records list that principal, Mohammed Shuwaideh, as a deputy squad commander with engineering expertise.

Mr. Lazzarini, the UNRWA official, said that the mere existence of an adjacent shaft did not necessarily implicate the principal. Nevertheless, on Nov. 13, the same day that The Times questioned UNRWA about Mr. Shuwaideh, he was put on administrative leave.

The United Nations has no way to verify that its employees are not members of Hamas or other militant groups, said James Lindsay, who served as UNRWA’s general counsel until 2007.

“The U.N. has been unable and or unwilling to eliminate Hamas militants and their supporters, as well as those from other terrorist groups, from their ranks,” Mr. Lindsay said. “UNRWA hiring practices and the makeup of the labor pool from which UNRWA draws its employees suggests to me that the numbers the Israelis are talking about are probably pretty close to the truth.”

Even for criminal background checks, UNRWA relies on employees to self-report and provide confirmation of a clean record by way of a letter from the “de facto authorities.” In Gaza, that means Hamas, and before Hamas took over in 2007, it meant the Palestinian Authority.

The most serious effort to investigate potential Hamas members within the agency’s employees came after Israel accused the 18 UNRWA workers of involvement in the Oct. 7 attack. In those cases, Israeli officials said they provided video and sensitive intelligence that they say backed up their claims. (A 19th name was dropped after officials said he was misidentified.)

For nine of the workers, the U.N. Office of Internal Oversight Services said there was insufficient evidence to take action. But a copy of its report, which was never made public, says it did not consider evidence that Israel provided about their “alleged membership of the armed wing of Hamas or other militant groups.”

U.N. investigators ultimately only found that the other nine “may have” been involved. (In one case, investigators were shown video of the worker throwing a dead Israeli into an S.U.V.)

Still, an UNRWA spokesman said that almost all of the employees were terminated or put on leave.

Khalil al-Halabi, a former UNRWA official in Gaza, argued that punishing the entire agency and everyone it serves over the misdeeds of some employees was unfair. But he said that the actions of militant-linked workers were causing enormous damage to the agency.

“It’s a disaster,” said Mr. al-Halabi, who has been critical of the Oct. 7 attack. “They’re essentially giving Israel a pretext to shut UNRWA down.”

Jo Becker is a reporter in the investigative unit at The Times.

Adam Rasgon is a reporter for The Times in Jerusalem, covering Israeli and Palestinian affairs.