The Justice Department on Friday filed criminal charges against Jack Teixeira, a 21-year-old member of the Massachusetts Air National Guard, accusing him of leaking U.S. classified documents that detailed everything from Ukraine battlefield assessments to covert surveillance of American allies.

A day after his arrest by federal agents, Airman First Class Teixeira appeared in a Boston courtroom on Friday morning, handcuffed and wearing a beige prison uniform. He was charged with two separate counts related to the unauthorized handling of classified materials and faces a maximum sentence of 15 years if convicted.

Judge Paul G. Levenson ordered Airman Teixeira, who did not enter a plea, to remain in custody and scheduled a follow-up hearing on Wednesday.

In an 11-page complaint unsealed after the hearing, an F.B.I. special agent with the bureau’s counterintelligence division in Washington detailed much of what has already been reported publicly: that Airman Teixeira used his access to sensitive information as a computer network specialist to post documents bearing top secret markings to an online gaming chat group.

Even with legal proceedings underway in a leak case that blindsided the Biden administration and may have jeopardized its sensitive intelligence activities, the hard work for U.S. officials was just beginning as they reviewed security protocols across the government to figure out how to prevent yet another mass disclosure of federal secrets.

President Biden alluded to that difficult task in a statement issued later Friday, in which he commended the fast work of law enforcement in identifying and arresting Airman Teixeira.

“While we are still determining the validity of those documents, I have directed our military and intelligence community to take steps to further secure and limit distribution of sensitive information,” the president said.

Mr. Biden added that his national security team “is closely coordinating with our partners and allies.” The leaks have prompted concern in foreign capitals that intelligence shared with Washington might be subject to exposure, and has caused embarrassment over the reminder that the United States spies on even its close allies, including South Korea and Israel.

In later remarks to reporters, Mr. Biden added that he had instructed officials to get “to the root of why he had access in the first place.”

The Pentagon has provided little information about what security reviews might be underway. In a statement issued after the arrest on Thursday, Defense Secretary Lloyd J. Austin III said he had directed a review of intelligence access, accountability and control procedures to “prevent this kind of incident from happening again.”

One key question will be whether a security lapse might have allowed the documents to be taken off the base, or whether the disclosures point to a systemic problem, such as the sheer number of people with access to classified information. That reality has allowed other young government employees, including the former National Security Agency contractor Edward Snowden and the former Army intelligence analyst Chelsea Manning, to obtain and distribute large numbers of highly sensitive documents with no direct relation to their job duties.

While Mr. Biden’s remarks were directed widely to the military and intelligence agencies, officials said that based on what is known so far, the Defense Department will make the initial moves to tighten security. Officials described a reluctance to limit intelligence shared with the Pentagon and said it is more likely that the first steps of any security review will focus on improving how the military gives access to the material.

Top Republicans on Friday praised the arrest of the airman even as Speaker Kevin McCarthy accused the Biden administration of having been “asleep at the switch” on protecting the nation’s secrets. But Representative Marjorie Taylor Greene of Georgia went further, calling Airman Teixeira a “hero” who had exposed government secrets the administration has tried to conceal and who was being unfairly targeted for his right-wing views.

Airman Teixeira was assigned to the 102nd Intelligence Support Squadron, a component of the 102nd Intelligence Wing, headquartered on Otis Air National Guard Base on Joint Base Cape Cod in Eastern Massachusetts. He was trained as what the military calls a “Cyber Transport Systems Journeyman,” or a specialist responsible for helping to maintain the force’s communication networks.

According to an Air Force career website, all “cyber transport system” airmen must pass the kind of background investigation required for a top-secret clearance, which allows them to work on computer networks carrying the most sensitive data.

Airmen assigned to the 102nd Intelligence Wing and the 102nd Intelligence Support Squadron produce intelligence reports from data collected by a variety of sensors on the U-2, RQ-4 Global Hawk, MQ-1 Predator, MQ-9 Reaper and other intelligence and reconnaissance aircraft and systems, U.S. military officials said on Friday.

Airman Teixeira was a computer systems technician supporting the analysts compiling those reports, one official said. Unlike many reservists who deploy overseas when mobilized to active duty, Airman Teixeira and other members of his unit could do all assigned work at their home base on Cape Cod.

A Justice Department charging document filed on Friday said an online associate of Airman Teixeira told F.B.I. agents that the young guardsman had begun sharing classified information in an online chat room in December, first as “paragraphs of text.” Beginning in January, it said, the airman began posting images of raw intelligence documents that he printed out in his workplace, furtively brought home and photographed for uploading.

Those details match accounts of law enforcement officials and of Airman Teixeira’s online associates who were interviewed by The New York Times, although they said his leaking began no later than October. They said he initially confided in a small group of like-minded people who discussed shared interests, including military hardware and gaming, in an invitation-only chat group on Discord.

Hundreds of classified documents were shared, group members and law enforcement officials said, including detailed battlefield maps from Ukraine and confidential assessments of Russia’s war machine.

His goal, group members said, was both to educate and impress.

Some of the uploaded documents, the Justice Department said, contained information “used to inform senior military and civilian government officials” during briefings at the Pentagon.

The complaint said the F.B.I. was able to identify Airman Teixeira after learning his user name on what it called “Social Media Platform 1” from an associate and obtaining records from the company showing that it was tied to an account he created using his real name and address in North Dighton, Mass.

The federal charging documents indicate that Airman Teixeira was granted a top-secret security clearance in 2021, which was required for his job as a computer network technician.

While that may sound like an exceptional degree of access for a junior-ranking service member, having top secret clearance in that job is perfunctory. Pentagon officials say the number of people with such access is in the thousands, if not tens of thousands.

The affidavit states that he was granted access to what is called sensitive compartmented information, or SCI, which typically tells a user how the intelligence was derived — such as the use of human spies or signals intercepts.

The most common network used by Defense Department employees who work with intelligence is the Joint Worldwide Intelligence Communications System, or JWICS — pronounced “JAY-wicks.”

Much of the material in the leaked files appears to be information that would be readily available to anyone with access to a JWICS computer terminal, through which users can visit “portals” — essentially websites — for the various agencies of the intelligence community as well as many individual military units.

The C.I.A. and Defense Intelligence Agency’s own secret-level and top-secret-level portals typically contain short vignettes on world events on their home pages, divided by geographic region and topic area.

Outputting those files is as easy as hitting “print” on a JWICS terminal that is connected to a printer.

Patrick M. Lueckenhoff, an F.B.I. special agent, told a federal judge on Friday that there was probable cause to believe Airman Teixeira had violated two parts of Title 18 of the federal code.

Section 793, better known as the Espionage Act, is part of a World War I-era law that criminalizes the mishandling of closely held information related to national defense that could be used to harm the United States or to aid a foreign adversary. A conviction carries a prison sentence of up to 10 years per violation.

Mr. Lueckenhoff said Airman Teixeira had violated two separate provisions of Section 793. One covers the unauthorized retention of such information, and the other covers the transmission or disclosure of the information to a person who is not authorized to receive it.

Section 1924 criminalizes the mishandling of classified information. It is punishable by a fine or a prison sentence of up to five years.

The charging documents say that Airman Teixeira was aware of the consequences of his actions, and even used his government computer to search classified intelligence for the word “leak” on April 6, around the time the existence of the leaked documents became widely known.

There is reason to believe, the complaint says, that he was searching for classified reporting regarding the leak investigation as well as information about the intelligence community’s assessment of the leaker’s identity.

Julian E. Barnes, Helene Cooper, Karoun Demirjian, John Ismay, Jenna Russell, Charlie Savage, Eric Schmitt and Glenn Thrush contributed reporting.