THE MEXICAN GAS DEAL has been concluded -- just in time for Mexican President Jose Lopez Portillo's visit here. The haggling had, in truth, gone on more than long enough. This episode illustrates the extraordinary hazards of trying to buy and sell energy in direct negotiations between governments. The tradition of price regulation makes that inevitable, unfortunately, when this country imports natural gas. But the Mexican experience stands as a warning against the idea, which keeps bobbing up in Congress, of extending federal authority to oil imports.

The Mexican gas will actually be bought by a consortium of American pipeline companies headed by Tenneco Inc. But the federal government has to approve the price and, when the sale was first announced two years ago, the Energy Department vetoed it. The secretary of energy, James R. Schlesinger, resisted -- wisely, as it turned out -- setting a precedent of a gas price tied to oil. He also knew that the Canadians, who export large amounts of gas to the United States, would immediately raise their prices to the level approved for Mexico. Above all, he feared that a high Mexican price would jeopardize the anguishingly uncertain progress through Congress of the natural gas pricing bill that was finally enacted late last year. From the American perspective, those were all respectable grounds for a veto.

But they enraged the Mexicans, who saw their own long-term interests sacrificed to the immediate tactical necessities of the Carter administration in dealing with other suppliers, and with its own domestic opposition. The United States had originally taken a rather light-hearted attitude toward the veto, reasoning that the Mexicans had no other customer for the gas. The Mexicans responded by revising their plans to expand their own consumption and reduce exports. The cancelled 1977 sale contemplated volumes eventually up to 2 billion cubic feet a day. The present sale will be 300 million cubic feet a day -- just over half of one percent of current American consumption.

The United States has wanted to limit the negotiations to gas. The Mexicans see gas as only one item on an agenda that ranges from the trade in winter tomatoes to Mexican workers' migrations across the Rio Grande. Meanwhile, this country continues to import large volumes of Mexico's oil on a purely commercial basis, with prices set by the world market. For all of the oil companies' sins, they provide a useful buffer between governments with conflicting views of the world.

The Mexican gas will cost less than it would under the vetoed 1977 contract. But it will cost more than most domestic gas, and it will raise some consumers' bills a little. That demonstrates the way the world is currently working. If Americans want more energy, they are going to have to pay more for it -- and, as it turns out, pay quite a lot more.