TOKYO — Prime Minister Shinzo Abe of Japan and the leader of the southern island Okinawa agreed on Friday to take a dispute over the future of a United States military base out of the courts and back to the negotiating table.

Mr. Abe accepted a freeze on construction work at a contentious new location planned for the base, Marine Corps Air Station Futenma, as part of the agreement with Okinawa’s governor, Takeshi Onaga. Work had already been disrupted while the authorities in Tokyo and Okinawa fought a legal battle over the site.

The deal is the latest twist in a 20-year effort by Japanese and American officials to move the base, which is in the middle of a crowded Okinawan city. National officials want to move the base to a less crowded part of the island, but Mr. Onaga and a majority of Okinawans oppose the plan because they want the Marines moved off Okinawa altogether.

“If the present situation continues, and we keep up an endless battle in the courts, things will simply become deadlocked,” Mr. Abe said. Television footage showed Mr. Abe and Mr. Onaga shaking hands over the deal at the prime minister’s office in Tokyo.