At the fragile age of nine months, Panamanian democracy has entered a contest for survival pitted against large foreign debts and the specter of return to overt military rule.

The struggle of Nicolas Ardito Barletta, an economist who is Panama's first elected president in 16 years, is to guide the country back to solvency through painful measures while also avoiding political violence that could bring the soldiers out of their barracks again.

"The opportunity for democracy has come at a very difficult economic moment, and unless the United States helps, we're going to go back to military dictatorship," Ardito Barletta warned in an interview. "The most important thing to strengthen the democratic process is to show we can do something to resolve our economic problems."

Few doubt Ardito Barletta's economic ability. But increasingly, friends as well as foes have begun to ask whether he has the political agility to put it into practice.

Ardito Barletta's task is similar to that faced by other new civilian governments replacing military rule in a trend hailed by the Reagan administration as progress in the effort to restrict Marxist influence in the hemisphere. It also is an early testing ground for repeated assertions by President Fidel Castro of Cuba that the democratic Latin governments cannot pay their debts to U.S. banks without risking violence in the streets.

In some ways, the president seemed an ideal candidate for the challenge of dealing with Panama's $3.7 billion debt and moving the government out from under military tutelage. Ardito Barletta, 46, earned an economics doctorate at the University of Chicago -- studying under professor George P. Shultz -- served as planning minister under the late general Omar Torrijos and was vice president for Latin America at the World Bank until he was called home last year.

Reflecting this experience, Ardito Barletta and President Miguel de la Madrid of Mexico have begun soundings with other Latin leaders to put together a technical proposal aimed at postponing interest payments to U.S. banks, a high Panamanian official said.

Panama, for example, has found increasing difficulty meeting interest obligations of $400 million per year, which gobble up 35 percent of its export earnings. The proposed breathing spell, although not so designed, would in effect be a response to Castro's campaign for the debts' cancellation or assumption by the U.S. government.

At home, dealing with the debt has meant pushing unpopular tax increases and public spending cuts as well as tariff reductions and changes in the country's stringent labor code that affect some of Ardito Barletta's constituency.

Although designed for uncontested economic goals, his proposals have been fought over in a political atmosphere charged with the legacy of Torrijos' populist dictatorship and the military rule following his 1981 death.

Ardito Barletta, for example, was chosen as candidate for the ruling Democratic Revolutionary Party by Gen. Manuel Antonio Noriega, commander of the Panamanian Defense Forces. He was elected in May 1984 by a margin of only 1,713 votes out of 600,000 cast -- and only after Noriega stopped the count with Ardito Barletta's opponent in the lead.

Since taking over in October with what many Panamanians called a fraudulent mandate, Ardito Barletta and his top aides have continued to meet on Tuesday mornings with Noriega and his military staff to discuss government business.

Against that background, Ardito Barletta has had difficulty establishing authority. The opposition Christian Democratic Party charged this weekend, for example, that Noriega and his officers are the president's "only real support."

Political and business leaders said Ardito Barletta also has contributed to his lack of political authority by failing to enlist support of potential allies. As a minister under Torrijos and later as a functionary in the World Bank, Ardito Barletta never learned the value or tactics of building political support through compromise, they explained.

"Our feeling is first he is a banker, second he is an economist and third he is a president, and we want him to be a president," said Carlos Hoffman, president of the National Private Enterprise Council.

Fresh from six years at the World Bank, Ardito Barletta declared a national emergency and tried to push through an immediate tax reform. Frustrated by lack of support from a political class used to decrying or defending the military, he had to water down the changes before getting them passed months later.

"I had problems with it because of the way I did it," Ardito Barletta acknowledged.

Last month, Ardito Barletta's plan for revising the protective labor code was sent to Legislative Assembly members for private discussions. It promptly was published in a local newspaper and union leaders, professing outrage, called a general strike.

The strike July 1-2 was only partly effective. But it was politically costly. Troops called out to control demonstrating students used shotguns to disperse the crowd. The birdshot injured a number of youths, including a bystander who Ardito Barletta said remains hospitalized in danger of death.

Few Panamanians, including labor leaders speaking privately, disagree with the idea of changing the labor laws. The code makes severance payments so high that Panamanian businessmen are reluctant to hire workers even when they need them, contributing to an unemployment rate estimated at 22 percent.

Pablo Duran, who manages a family coffee enterprise, said he has permanently hired only 10 percent of his 1,000 employes to avoid the law's bite. The rest, he said, are hired and fired every three months.

Although labor and business leaders acknowledge the need for change, they have undertaken contacts to coordinate against the government in a national dialogue scheduled to begin this week on the labor bill, along with tariff reductions. The idea is to have business leaders support union opposition to changing the labor code in return for union support in the fight against tariff reductions.

Ardito Barletta has undertaken these measures as part of a refinancing agreement made last month with the International Monetary Fund and private banks, according to General Manager Luis Alberto Arias of the National Bank of Panama. As he begins the national dialogue, however, businessmen are complaining that Ardito Barletta has refused to reveal details of commitments in the debt renegotiation.

Panamanians and foreign observers said Noriega has been disappointed with Ardito Barletta's performance but remains committed to the elected presidency, making a coup d'etat unlikely for the moment. But further turmoil or a breakdown in handling the debt could change the military's mind, they said.

"Barletta is only the manager of the farm; he is not the owner," said Fernando Nunez, a radio commentator and friend of the president. "If he can't take care of the cows, he's got to go."