The election was fought over the fate of Marine Corps Air Station Futenma, a particularly unpopular base whose aging runway is surrounded by homes and schools in the middle of the densely populated city of Ginowan. Mr. Nakaima, 75, was supported by Prime Minister Shinzo Abe, who has tried to restart an almost two-decade-old plan to move the base to a less-populated spot on the northern end of the island near Henoko, a village in the city of Nago.

Mr. Onaga campaigned on a platform of opposing the relocation, calling for the airfield to be moved off the island altogether. Two other minor candidates also staked out positions on what to do about the Futenma base, a highly emotional issue that has become a rallying point for Okinawan anger at the noise, pollution and crime brought by the American presence.

While Mr. Onaga’s victory was not a surprise — he had been leading in polls — political analysts called it a blow to budding hopes in Tokyo and Washington that Mr. Abe might finally get the new base built. The United States and Japanese governments first agreed in 1996 to relocate the airfield to an American base called Camp Schwab, near Henoko, but stiff local opposition has blocked the move.

The project seemed to take a big step forward in December when the prime minister persuaded Mr. Nakaima to drop his opposition to the relocation and approve a contentious landfill permit. Mr. Abe, who has vowed to build closer military ties with the United States, won over Mr. Nakaima with offers of more than $3 billion in public works projects for Okinawa, including the construction of a second runway at Naha’s busy airport.

Despite Mr. Nakaima’s defeat, analysts said Mr. Abe could still try to move ahead with the construction of the new Marine airfield because his government already has the permit to begin filling in the sea for its twin runways. But doing so would require him to push past the opposition of both the new governor and the current mayor of Nago, who won re-election in January.