Julian Assange, the founder of WikiLeaks, agreed to plead guilty on Monday to a single felony count of illegally obtaining and disclosing national security material in exchange for his release from a British prison, ending his long and bitter standoff with the United States.

Mr. Assange, 52, was granted his request to appear before a federal judge at one of the more remote outposts of the federal judiciary, the courthouse in Saipan, the capital of the Northern Mariana Islands, according to a brief court filing made public late Monday. He is expected to be sentenced to about five years, the equivalent of the time he has already served in Britain, according to a law enforcement official familiar with the terms of the agreement.

It was a fitting final twist in the case against Mr. Assange, who doggedly opposed extradition to the U.S. mainland. The islands are a United States commonwealth in the middle of the Pacific Ocean — and much closer to Mr. Assange’s native Australia, where he is a citizen, than courts in the continental United States or Hawaii.

Shortly after the deal was disclosed, WikiLeaks said that Mr. Assange had left London. Mr. Assange is scheduled to appear in Saipan at 9 a.m. local time on Wednesday and is expected to fly back to Australia “at the conclusion of the proceedings,” Matthew J. McKenzie, an official in the Justice Department’s counterterrorism division, wrote in a letter to the judge in the case.

Early on Tuesday morning, his wife, Stella Assange, posted a video of her husband signing paperwork and boarding a plane on Monday.

Barring last-minute snags, the deal would bring to an end a prolonged battle that began after Mr. Assange became alternately celebrated and reviled for revealing state secrets in the 2010s.