A frost in U.S.-Mexican relations early this year has thawed somewhat after both countries, seeking to avoid confrontation, acted to ease tensions, Mexican and U.S. officials said.

The U.S. government has toned down in recent weeks comments on such problems here as drug trafficking and assaults on tourists. The Mexicans have moderated their public complaints about U.S. "intervention" in Mexican affairs, and the government has advised the media to soften criticism of Ambassador John Gavin, Mexican officials said. A long delayed bilateral trade accord was signed in late April.

But it is too early to say whether the improvement will be permanent following a serious dispute three months ago over narcotics trafficking, according to officials of Mexico's governing Institutional Revolutionary Party, academic specialists in U.S.-Mexican relations and diplomats. The flare-up illuminated an overall heightening of tensions between the two countries during 1984, the sources said.

The two countries' diplomats "don't say it publicly, but there has been a serious deterioration in relations with the United States," said a Mexican party official, who requested anonymity.

In this view, disputes on issues ranging from immigration control to the ambassador's feisty style built up to what Mexican officials privately termed a "crisis" in February, when Washington ordered vehicle-by-vehicle searches of Mexican cars and trucks entering the United States.

Such extensive checks had not been seen since an antidrug campaign, nicknamed Operation Intercept, during the first Nixon administration. Then, most checks were of U.S. vehicles returning home.

The U.S. measure was designed to pressure the government here to speed up the investigation of the killing of a U.S. Drug Enforcement Administration officer. Mexican officials said they were particularly irritated that Washington did not give them advance notice.

"Within these last months, U.S. actions against Mexico have hurt the Mexicans' pride," a senior Mexican administration official said. Gavin said that relations were good overall, but he noted that the DEA agent's case "brought to a head some very serious problems" regarding narcotics trafficking.

Washington has displayed "an irritating change in public attitudes and in the official responses to what happens in Mexico, passing from a benign indifference to a unilateral protectionism," wrote Wayne Cornelius, director of a U.S.-Mexican studies department at the University of California at San Diego, in the May issue of the Mexican magazine Nexos. He said the United States was showing "a renewed interventionist impulse."

Both governments agree that friendly ties are a high priority for myriad reasons. The two countries share a 1,800-mile border crossed each year by millions of tourists, most heading south, and millions of job-seekers heading north. Mexico is the number one supplier of oil to the United States, and U.S. banks hold the largest share of Mexico's $95 billion foreign debt.

It is widely recognized that nationalism frequently leads Mexicans to bridle at even minor indications that its wealthy, superpower neighbor is trying to push it around.

"Maybe what they mean is that we treat them as if they were grown-ups," Gavin said in an interview when asked about suggestions that the United States has been using more muscle.

Some observers say a change in attitude started last summer, when the U.S. Congress came close to approving the Simpson-Mazzoli bill, a sweeping proposal to curb illegal immigration. Mexico opposed it, largely because emigration helps ease problems of unemployment and overpopulation and because of what was called the debate's "anti-Mexican tone."

Even though the bill died, the government was unhappy that the United States even considered it.

In September, attention turned to a public statement by Gavin that the U.S. government was considering issuance of a formal travel advisory to warn tourists about dangers of visiting Mexico. It would have been the first since 1976, and was perceived as a serious threat to the tourism industry, Mexico's second-largest source of foreign exchange.

The ambassador's statement was prompted principally by foot-dragging by Mexican authorities in investigating cases of killings and other crimes against U.S. citizens, American officials said. Mexico responded that the number of crimes is not excessive compared with the number of tourists, although at Gavin's suggestion the government began a program to help foreigners get legal assistance.

The embassy and State Department now are fighting congressional proposals to declare a travel advisory. The publicity has led some insurance companies to refuse coverage for tour groups visiting here.

Gavin's activities sparked another dispute later in the autumn, when he had lunch in the northwestern state of Sonora with local authorities who were members of the opposition National Action Party. The governing party, which faces a major challenge in Sonora from National Action in July 7 elections, accused the ambassador of intervening in Mexican politics by purportedly showing favor for the opposition.

The ruling party clearly played up the incident for political advantage. It regularly tries to paint National Action, a conservative group, as a pawn or an agent of U.S. interests. Representatives of the ruling party also were scheduled to attend the luncheon but canceled at the last minute, U.S. officials said.

Gavin has become an issue, in part because he regularly responds in strong terms to public criticism. In an incident last month, which contrasted with the recently improved tone but was typical of earlier exchanges, Mexican Sen. Gonzalo Martinez of the Senate's foreign relations committee, accused the envoy of "belligerence and lack of common sense." Gavin immediately had the embassy respond with a statement rejecting the remarks as "unfounded and scurrilous."

Asked why he responds to criticism in such terms, Gavin said, "We do not believe that playing scapegoat for certain elements in this society leads to a mature relationship. We do believe that respect is a two-way street."

A Mexican administration official credited Gavin with defending Mexican interests against what he called the "hard-liners in Washington," but he said that the ambassador's "style" hurt relations. "He's very imprudent. That's his main problem," said the official, who declined to criticize Gavin on the record.

The issue of personal attacks on Gavin became serious enough that it was raised at a meeting in early April between the ambassador and President Miguel de la Madrid, according to a reliable source. At that meeting, the source said, "it was recognized at the highest level that it is not helpful to continue these attacks" against the ambassador.

That meeting appears to have contributed to the recent mellowing. Other factors were arrests of three accused leading drug traffickers and the signing of a trade accord.

One measure of the degree of concern was a government request to newspapers not to publish the ugly caricatures of Gavin and of President Reagan that had been appearing, a Mexican official said.