Spain's leftist parties, launching a last-ditch effort to forestall the Madrid government's plans to seek an early entry into the North Atlantic Treaty Organization, today began campaigns calling for a national referendum on the issue.

But even as the opposition promised hundreds of public meetings across the country and motorcades in every major town to gather signatures opposing NATO membership, the government won the green light from parliament for a straight debate and vote to endorse its policy.

Recognizing that NATO is a divisive issue in Spain, the government has consistently rejected demands by Socialists and Communists for a plebiscite.

The debates in Congress and the Senate, where the ruling Union of the Democratic Center party holds a working majority, are expected before the end of this month.

Anticipating the parliamentary support for the government's plans, diplomats renegotiating the Spanish-U.S. bilateral defense pact today quietly prepared to wind up the discussions with an agreement to prolong the defense treaty until April, when it will be viewed within the NATO framework. The present treaty, which is due to expire Sept. 21, covers four U.S. bases in Spain.

Although Spain is bracing for public squabbling about the NATO issue in the coming weeks, leftist politicians admit that entry is a foregone conclusion.

Socialist Sen. Fernando Moran, a senior foreign affairs spokesman in the opposition party, said the most that his group could hope for was to "psychologically defeat the government" by ensuring that Spanish presence in NATO remained unpopular among voters.

The Socialist leadership also appeared to have backed down from earlier pledges to withdraw immediately from NATO should it come to power. Unveiling the campaign opposing NATO membership, Felipe Gonzalez, leader of the Spanish Socialist Workers' Party, indicated at a press conference that if his party were in power it would seek a referendum on the NATO issue.

A government adviser said the campaign by the Socialists appeared to be "cosmetic and playing to the gallery." Government circles believe that despite the promised energy of the anti-NATO propaganda, the leftist campaign has started too late to trouble the entry plans seriously.

Seeking to disassociate himself from a parallel campaign by the Communists of blanket opposition to NATO, Gonzalez said he was not against the Atlantic Alliance, but he did not believe it was necessary that Spain be a member. Gonzalez said Spain's interests and Spain's contribution to Western defense would be better served through bilateral accords with the United States.

However, negotiations on renewing the 1976 U.S.-Spanish defense and cooperation treaty have been bogged down during the spring and summer by Spanish demands for increased aid and a greater participation in military technology. Details of the negotiations have remained secret, but Spanish diplomatic sources said another problem at the talks was Spain's determination to maintain a veto over the use of the bases and its threats to use the veto against U.S. operations in the Middle East.

The sources said that Spain had abandoned attempts to keep separate the bilateral talks and NATO entry because of the time factor. Spanish secretary of state at the Foreign Ministry, Carlos Robles Piquer, who is heading the Spanish team in the bilateral treaty talks, pointedly told Spanish radio last week that the United States was "more generous" to its allies in the NATO context.

Although the U.S. negotiators, led by the ambassador in Madrid, Terence Todman, have diplomatically refrained from pressing the NATO issue, the Spanish decision to bring forward NATO entry and review the bilateral situation later in the context of the alliance fits neatly with Washington's interests.

At the center of the government's hurry to join NATO is a basic belief that democracy in Spain will be shored up through the membership. Entry into NATO has been a policy objective of the ruling Union of the Democratic Center for the last four years, but the urgency set in after the attempted military coup in Spain in February. According to the party's foreign policy spokesman, Congressman Javier Ruperez, "Turkey and Greece show that NATO membership is not an insurance against coups, but through NATO we will have the Spanish military traveling and thinking in terms of strategy and a common enemy abroad instead of inside Spain."

Such thinking has led government officials to believe that for all the rhetoric of the Socialists' anti-NATO stand, the issue will in time be less virulent and that the more moderate members of the opposition will in time accept the advice of France's Socialist foreign minister, Claude Cheysson, who recently urged his Spanish colleagues to reconsider their objections to NATO and accept membership.