The United States secured a semifinal berth in the Davis Cup tennis tournament when Tim Mayotte defeated Mexico's Leonardo Lavalle, 7-5, 4-6, 0-6, 6-4, 9-7, yesterday in Mexico City.

Mayotte's victory gave the U.S. team an unbeatable 3-1 lead in the best-of-five-match quarterfinals. Brad Gilbert easily won the last match of the series, 7-5, 1-6, 7-5, over Francisco Maciel, for a final score of 4-1.

Mayotte's victory, which avenged his singles loss to Maciel Friday, advances the United States to a semifinal series in Australia. Australia defeated Britain, 4-1, in another weekend series.

In the other semifinal, defending Davis Cup champion Sweden, a 5-0 winner over Italy, will play in Czechoslovakia, which beat Yugoslavia, 5-0.

Service difficulties contributed heavily to Mayotte's loss to Maciel and he had more yesterday.

Despite five double faults, he won the first set by breaking Lavalle three times.

In the second set, the 8,000 mostly Mexican fans at Mexico City's Sports Palace interrupted play so many times with cheering that referee Francis Patrick Loderop penalized Lavalle one point and threatened to disqualify the Mexican team.

Mayotte, visibly angry with the crowd behavior, argued with some fans in the front benches. He had three double faults in losing the second set, then had three more while being blanked in the third set.

At one point in the third set, Mayotte became so upset by his service troubles that he threw himself down on the clay court in frustration.

But he regained his composure, breaking Lavalle twice each in the fourth and fifth sets to pull out the victory.

In London, the Australians, who had guaranteed their place in the semifinals when they took an unbeatable 3-0 lead Saturday, split yesterday's two best-of-three-set singles. Pat Cash defeated Briton Andrew Castle, playing in his first Davis Cup, 8-6, 6-4. Britain's Jeremy Bates came back from a one-set deficit to defeat Paul McNamee, 3-6, 6-2, 6-4.

In Bastad, Sweden, Stefan Edberg defeated Davis Cup rookie Paolo Cane, 6-3, 2-6, 6-0, and Mats Wilander beat Claudio Panatta, 6-4, 6-3.

In Sarajevo, Yugoslavia, Milan Srejber defeated Slobodan Zivojinovic, 8-10, 6-2, 15-13, and Miloslav Mecir beat Igor Flego, 6-2, 7-5, to complete Czechoslovakia's sweep.