Japanese Prime Minister Yasuhiro Nakasone has failed in his latest attempt to formally scrap a 9-year-old defense spending ceiling but has won a compromise that many analysts here say will, in time, achieve the same thing.

Last week, after long deliberations, elders of the ruling Liberal Democratic Party deferred a decision -- taken as a way of saying no -- on the fate of the ceiling, which holds defense spending to 1 percent of gross national product.

But they agreed to devise a 5-year military spending program and give it the force of Cabinet policy. If the sums for that program now being discussed inside the party and government are adopted, the effect could be to push spending beyond 1 percent, although not by much.

Nakasone had been campaigning forcefully to end the ceiling. By some accounts, he told associates that it was a major goal of his administration.

"He had been having more confidence about his prestige, about his power, about the support of politicians," ruling party Sen. Ichiji H. Ishii said.

But rivals within the party and even some of his friends appear to have felt Nakasone was defying the slow, consensus-building ritual that Japanese politics traditionally requires. "It seems Nakasone took this rule lightly," editorialized the Asahi Shimbun newspaper.

The Japan Economic Journal said Nakasone's behavior "has invited very strong repercussions from inside the party. Its general mood turned to block Nakasone's wishes."

While it was a significant blow to his personal standing, few expect it to jeopardize his hold on his office. Nakasone, the most enduring prime minister since Eisaku Sato quit in 1972, is nearing the start of his fourth year in office.

Japan's defense spending, totaling about $13 billion this year, amounts to only about 0.997 percent of GNP, compared to about 7 percent in the United States.

The ceiling was adopted by the Cabinet in 1976. But critics such as Nakasone contend that defense spending should be governed by Japan's defense needs.

Washington has for years pressed Japan for higher spending. Many analysts say Nakasone's decision to press the issue now was intended in part to ease pressure in Congress to pass legislation aimed at reducing Japan's trade surplus with the United States.

Any alteration of the limit, however, is highly controversial. Opposition parties call it a first step toward reviving World War II militarism. Many members of the ruling party see it as tampering with a formula that has contributed to Japan's economic prosperity.

Nakasone's new campaign began last spring, when his party pushed through parliament a defense budget that was expected to break the ceiling unless legislators later took the extraordinary step of denying soldiers a routine pay raise.

In private meetings in recent weeks, Nakasone had called on party leaders to scrap the ceiling and do it publicly. In its place he proposed a spending limit for a 5-year period.

In last week's compromise, Nakasone won only the 5-year plan. Official government policy is still to respect the 1 percent cap pending reconsideration later in the year.

For the 5-year plan, the Japanese military establishment is pushing for a total of about $80 billion. Keeping spending to 1 percent of GNP, according to estimates here, would result in outlays of only about $73 billion.

The 1 percent debate is hypothetical, however, because no one knows with certainty how fast Japan's GNP will grow.

Matters were further complicated over the weekend when a senior party leader suggested publicly that it might be wise to defer the military pay raise, so as to continue to respect the 1 percent limit.