RIO DE JANEIRO, OCT. 25 -- Brazil's growing commercial prowess and its lingering trade barriers have brought it into repeated confrontations with the United States, making bilateral relations tense.

Once joined in a relatively harmonious trading alliance, these two economic powers have entered into a period of strain that is generating anger on both sides. How this difficult relationship is managed, say politicians and diplomats in both countries, will help determine the outcome of a crucial debate here between protectionists and free-traders over Brazil's future economic policy.

The tensions also are testing Washington's ability to shift from a historical role as an economic patron of Brazil to a more balanced one as partner. Lately, the transition has been anything but smooth.

The industrial surge in Brazil over the past two decades and its aggressive export drives have brought U.S. pressure on Brazil to accept quotas on steel and textile sales and to pay duties on shipments of ethanol and orange juice concentrate.

In turn, efforts by American firms to penetrate Brazil's infant computer industry have met with protectionist barriers. American pharmaceutical companies complain of official inaction against what they say is rampant pirating of drug formulas.

According to an inventory of global trade barriers kept by the Office of the U.S. Trade Representative, Brazil is now on a par with Japan among noncommunist countries most closed to imports. Commerce Department statistics show Brazilian companies to be the target of a substantial percentage of the antidumping charges and countervailing-duty petitions brought recently by American businesses against foreign firms.

On top of these trade disputes, Brazil's decision eight months ago to suspend payment on the $69 billion commercial portion of its $112 billion foreign debt -- the largest in the Third World -- has added to mutual feelings of irritation, misunderstanding and distrust in U.S.-Brazilian ties.

Typical of the crisis-prone nature of the relationship, two deadlines loom this week. Monday, the U.S. Interagency Country Exposure Risk Committee is scheduled to rule on whether to declare bank loans to Brazil "value impaired," which would require banks to set aside additional reserves.

Later, the Cabinet-level Economic Policy Council is expected to reconsider whether to take retaliatory measures against Brazil for refusing to license the sale here of a standard computer software manufactured by the Microsoft Corp., an American company.

The Microsoft issue is important not only in its potential to disrupt U.S.-Brazilian relations but also as a precedent-setting case in developing rules to govern the international spread of information technologies.

Brazil, groping for a democratic sense of itself after 21 years of military government, is both eager to assert its independence and quick to underscore its continued vulnerability. As politicians here draft a constitution meant to provide an economic and political blueprint for the future, officials are asking for understanding from foreign friends.

"The current difficulties we have with the United States derive from an identity crisis that exists in Brazilian society and has little to do with the United States itself," said a senior Brazilian official. "The problems have to do with our soul-searching, our efforts to define such basic things as the role of the state in the economy, the future structure of our government, the space for foreign investment and so on.

Brazilian officials warn that U.S. pressures, particularly retaliatory trade sanctions, risk a backlash that could infuse new laws with fiercely nationalistic, anti-American tones.

But the timing of Brazil's coming of age catches the United States at a sensitive moment as well. Heightened concern about the gaping U.S. trade deficit has lowered American tolerance for protectionism abroad. Relations with U.S. trading partners have become less magnanimous in general.

While supportive of Brazil's democratic development, U.S. officials are losing patience with what they regard as a self-indulgent, often purposefully combative attitude -- what one termed a kind of "hulking teen-ager" behavior.

"The Brazilians have reached a point where they have to take on more responsibility for the way they participate in the world," said a senior Reagan administration official in Washington. "They have to assume a leadership role commensurate with their economic strength and their historical aspirations."

The transformation of Brazil from simple coffee grower into the eighth-largest economy outside the communist bloc has been stunning. Today, its gross national product is larger than all other South American nations combined. Its leading television network, TV Globo, has the fourth-largest audience in the world.

Brazil remains the world's largest coffee exporter, but in addition, it is the second-largest producer of iron ore and soybeans, third in corn, seventh in steel, eighth in aluminum and ninth in cars.

U.S. markets are still the main outlet for Brazilian goods, as they have been since the late 19th century, now absorbing about 30 percent of all that Brazil sells abroad. But the mix of products has changed since the 1960s, when manufactured goods entered the flow and eventually surpassed traditional agricultural exports.

For a time in the 1970s, political frictions stemming from complaints by the Carter administration about Brazilian human rights violations and nuclear development policies soured the bilateral climate.

But today, relations are largely free of major political disputes. U.S. officials are sometimes nettled by Brazil's arms sales to the Middle East, its support of peace initiatives in Central America that do not fall in line with U.S. objectives, its reluctance to push for democratic transitions in Paraguay and Chile and its closer contacts with Cuba and the Soviet Union. But such diplomatic matters seldom generate serious U.S.-Brazilian confrontation.

At the same time, the absence of political conflict does not mean agreement. Brazil is perceived by American officials as distancing itself from the United States in international forums. It has strengthened ties with its Latin American neighbors and allied itself more firmly with nonaligned nations as part of an effort to become a major world player on its own terms.

Not always certain of its strength and aims, Brazil finds itself stretched uncomfortably between First World and Third, belonging fully to neither. Its advanced industrial parks and universities make it a formidable international competitor, while its vast burdens of misery, illiteracy and debt keep it reliant still on foreign aid.

Referring to this uneasy dichotomy, a Brazilian official acknowledged that his country often has a sense of not fitting well in the world. U.S. officials say many Brazilians want to be welcomed into the major leagues, but they also expect to receive the economic concessions, trade preferences and other breaks granted minor leaguers.

Brazil defends its protectionism as necessary to help generate trade surpluses to pay interest on the debt. Indeed, Brazil has been achieving large trade surpluses for the past few years by boosting exports and reducing imports. Its trade surpluses with the United States grew from $700 million in 1981 to a peak $5.6 billion in 1984 before declining to $3.5 billion in 1986.

But the trade barriers also are rooted in concerns of national security and sovereignty. Many restrictive trade practices predate Brazil's international payments crisis.

As U.S. and Brazilian officials worked to defuse the latest flashpoints over debt and computers, there was evidence of determination on both sides to avoid a showdown.

On the debt problem, Brazil was offering to make a token payment to get around Monday's regulatory deadline. Brazilian officials hoped to be able to continue talks on a proposed rescheduling agreement and possible phased lifting of the moratorium. But creditor banks were insisting on an immediate end to the moratorium. As a compromise, U.S. officials have suggested that Brazil resume debt payments but deposit them with the Swiss-based Bank of International Settlements until a new agreement is reached.

On the computer software case, Brazilian authorities held out little hope of a reversal in the specific ruling last July that blocked the licensing here of Microsoft's MS-DOS system. But there were feverish efforts in the Brazilian Congress to amend a pending bill on software in a way that would leave this country more open to U.S.-designed computer programs.

Whatever the outcome of these disputes, those involved in managing U.S.-Brazilian ties say more trouble down the road is a virtual certainty. "I don't think we can go back to the 1960s and before, when we had a sort of magic belief in international cooperation," said a senior Brazilian official here. "The events of the '70s and '80s have pushed aside the dream of smoothly incorporating the developing countries into the world order."