The United Auto Workers and General Motors Corp. last night reached tentative agreement on an emergency contract that, by some estimates, could save the company up to $2.5 billion in labor costs over the next 2 1/2 years. In return, the proposal includes a moratorium on plant closings and other steps to save jobs.

The contract, reached after a grueling 37-hour bargaining session at GM headquarters in Detroit, marks the second time in two months that the union's leadership has agreed to return some economic benefits to a major domestic auto maker.

Last month, UAW negotiators okayed a 31-month pact with Ford Motor Co. that is expected to save that company up to $1 billion over the life of the agreement. Rank-and-file union members overwhelmingly ratified the Ford contract in voting that ended Feb. 28. The agreement was signed March 1.

If auto industry analysts are right, and if the tentative GM agreement wins approval from the union's bargaining council and its rank-and-file members, the UAW would sacrifice up to $3.5 billion in benefits over the next 30 months at GM and Ford.

The union's 300-member GM bargaining council will meet Thursday in Chicago to consider the tentative agreement.

UAW President Douglas A. Fraser and Owen Bieber, who heads the union's GM division, last night emphasized the job security provisions.

"We've succeeded in achieving a series of breakthroughs on job security that will stop the hemorrhaging of GM workers' jobs," Fraser and Bieber said in a joint statement.

The union normally has 470,000 members at GM. But nearly 150,000 have been laid off during the current recession.

Fraser and Bieber said the union "won crucial protection" against "outsourcing"--the use of outside contractors, foreign and domestic, to make GM parts. The union also managed to get the company to rescind four of seven announced plant closings, the union leaders said.

GM, matching a provision in the Ford pact, also said it would place a two-year moratorium on future domestic plant closings.

Fraser and Bieber said the economic provisions in the GM contract--a freeze on basic hourly wages for the life of the agreement and the elimination of nine paid personal holidays for UAW members--also were based on concessions made to Ford.

Full details of the agreement were not available last night. But GM's demands were fairly well known. Sources close to the negotiations indicated that the company got most of what it wanted.

Besides the wage freeze and the sacrifice of personal holidays, other union concessions include:

A deferment of three cost-of-living allowances, each about 10 cents an hour, over the next nine months.

Lower wages and benefits for new hires for a yet-to-be revealed period.

The plants that will be kept open under the tentative agreement include GM facilities in Euclid, Ohio, Trenton, N.J., and two in Detroit--the Fort Street plant and plant No. 37.

There was also good news for workers at the company's Coit Road plant outside of Cleveland. The plant will be closed, but the affected workers can keep their jobs through transfers to other GM facilities.

Workers with 10 years seniority at two GM plants in California--Southgate and Freemont, both of which the company had planned to close--will receive a guaranteed income based on a percentage of their full-time salaries.

GM workers also won a profit-sharing plan, which will begin in 1983. Under the formula, based on a percentage of the company's assets and profits, GM's hourly workers, as a group, would have received $1.35 billion between 1976 and 1979.

GM made a relatively modest profit of $333 million last fiscal year. Ford lost $1.06 billion.

Both companies had sought labor cost reductions to stem operating losses and become more competitive with foreign car manufacturers.

Alfred S. Warren Jr., GM vice president for industrial relations, hailed last night's tentative accord "as a historic agreement, because it recognizes the unprecedented changes taking place in world competition, and brings GM management and GM employes together in a united effort to meet and overcome that competition."

GM had tried three times this year to win such an agreement from the UAW. One session ended in failure Jan. 20 after nine days of bargaining. A second round, doomed by a split among the union negotiators, ended Jan. 28.

The second round of talks was based on a plan to pass all labor cost savings to consumers in the form of lower sticker prices on GM cars and trucks. But that provision was buried when those talks broke down, and it was not resurrected in the third round.

This last round, partly brought about by GM's decision to close seven plants in the absence of a concession contract, was the most crucial.

Failure to arrive at an early agreement this time could have forced the company and the union to give up and wait until regularly scheduled bargaining in July to settle their differences. That delay could have lead to a strike that might have done more damage to the UAW than the current recession.

Fraser and other UAW leaders had said repeatedly that their bargaining strength with GM rested in their ability to reduce the company's average hourly labor cost of $19.80 per covered worker through wage freezes, reductions in personal holidays, and other concessions.

If September had rolled around without a contract, Fraser feared GM could have made unilateral demands for concessions.

The union would have been left with the unwelcome choice of agreeing to tougher concessions or going on strike. The UAW has a $400 million fund to wage a strike, but such a strike would be a "long and bitter" battle largely fought from a position of weakness, Fraser has said.

About 249,000 UAW members in the nation's auto factories are on indefinite layoff, including the 150,000 laid off at GM. Their absence has placed a strain on the UAW treasury, and the union does not want to aggravate that strain with a strike.