The United Auto Workers and General Motors Corp. reached tentative agreement tonight on a new three-year contract that averts a threatened walkout by 95,000 GM workers in a selective strike aimed at the company's best-selling cars.

The settlement, worked out several hours before a midnight strike deadline, spares the American economy a potentially jarring jolt during its slide into a recession but appears to offer little encouragement to the Carter administration's anti-inflation effort.

It is the first time in 15 years that the auto industry has avoided a strike against the union's target for negotiating an industry-wide contract -- in this case the biggest of the Big Three, the nation's largest corporation and the world's leading manufacturing company.

The contract now must be ratified by the UAW's more than 450,000 workers at GM, and negotiations must still be concluded at Ford Motor Co. and Chrysler Corp. Union leaders predicted this process will be completed without difficulty.

Neither the union nor the company would immediately release details of anything beyond pension provisions, but the contract is believed to embrace wage and benefit increases of about 33 percent over three years, putting it in the upper ranks of labor pacts negotiated this year.

The agreement also includes automatic recognition of the UAW as bargaining agent for workers at new GM plants. This was one of the union's principal non-economic bargaining goals, and is a significant victory for the labor movement in its thus far faltering efforts to organize the relatively union-free Sun Belt region of the country.

"It is an excellent settlement that will provie UAW-GM workers with greater job and economic security and our retirees with protection from the continued erosion in their standard of living caused by inflation," said UAW President Douglas A. Fraser and Irving Bluestone, UAW vice president for GM workers, in a statement announcing the settlement after nearly 37 hours of virtually nonstop bargaining.

"The fact that a settlement was reached without a strike is a credit to both parties," said George B. Morris Jr., the company's chief negotiator, "and averts a situation which could have had a serious impact on our employes, the corporation and the national economy." He said the agreement provides "substantial" increases in wages, in time off, and in pensions for future as well as present retirees.

Pensions were the UAW's chief target for contract improvement this year. It won major gains for future retirees as well as periodic increases in benefits for its nearly 150,000 current retirees at GM.

The company rejected the union's initial pension proposal for cost-of-living increases tied to active workers' wages, but agreed to lump sum increases of one-third or more over three years in most cases. For instance, benefits for a 69-year-old pensioner who retired before 1970 would be increased from $298.50 a month to $417 a month.

In a tradeoff for union gains, Morris indicated the company won concessions to improve productivity and curb absenteeism. Without disclosing details, he said, "I hope one thing we've accomplished is [resolving] our concern over the terrible problem of absenteeism."

For active workers, Fraser indicated the union accepted the company's offer to continue the annual 3 percent wage increase that has become customary for UAW contracts. Continued cost-of-living protection, along with the union's already expansive array of health and welfare benefits, is also guaranteed.

UAW workers at GM currently are paid more than $9 an hour in wages and about $6 hourly in benefits, one of the highest compensation levels for industrial workers in the United States.

At a press briefing, Fraser and Bluestone, beaming broadly, said there were tense moments in the talks when it appeared a breakdown might occur, even as late as today. But they said both sides were committed to trying to reach a strike-free settlement and praised their corporate counterparts' handling of the talks. Bluestone called it a "momentous agreement . . . a breakthrough" and predicted "overwhelming" ratification by rank and file auto workers by the end of the month.

Fraser said the contract won't be too expensive for Ford, but acknowledged that financially troubled Chrysler Corp. was "obviously . . . different situation." Fraser indicated earlier that financial concessions for Chrysler, which is seeking federal government assistance, would be explored by the union after the industry pattern was established with GM.

The agreement on automatic recognition would permit the union to become bargaining agent at new plants without the considerable expense and risk of a representation election. It is, however, subject to complex limitations imposed by federal labor laws and regulatory interpretations.

The recognition agreement is the final step in a long campaign by the 1.5-million-member union to overcome what it calls a "southern strategy" by the company to siphon jobs out of the highly unionized Midwest and Northeast and into the often anti-union Sun Belt. The agreement follows an earlier pledge by the company to keep hands off union organizing drives and a subsequent agreement to give preferential hiring rights to UAW members at new plants.

At least five of 13 new facilities that GM has built in the South since the early 1970s remain unorganized, and more Sun Belt plants are on the corporation's drawing boards. It was not immediately clear how the new agreement would affect already opened plants with organizing campaigns under way. Sources indicated the real focus of the automatic recognition is the future plants.