President Carter and congressional Democrats moved quickly yesterday to compromise differences on controversial Labor-HEW and public works money bills over which they had been fighting for more than a month.

The White House and the House Democratic leadership reached final measurefor the Departments of Labor and Health, Education and Welfare yesterday morning hours before debate on the measure was to begin on the House floor.

On the other side of the Capitol, Chairman John C. Stennis (D-Miss.) of a Senate Appropriations subcommittee announced yesterday that nine of 18 water projects that the President wanted halted had been cut from his subcommittee's version of the public works money bill.

The House version of that measure, approved Tuesday, contains all but one of the water projects on Carter's "hit list." But pro-Carter forces in a surprising show of strength proved Tuesday they had enough votes in the House to prevent a veto override.

Thus if the Stennis subcommittee's recommendations are followed by the full Senate, a House-Senate conference would be in position to take out up to nine projects to make the measure more acceptable to Carter.

"Nobody would win as a result of a veto," Stennis said in announcing the subcommittee's action.

On the Labor-HEW bill, the President, according to informed sources, backed away from his opposition to the House Appropriations Committee's version of the bill. He earlier had criticized it for containing $1.4 billion more for HEW than he had recommended.

Under the agreement, the White House would not support any amendments to cut the present House bill and the House leadership would oppose any efforts to increase any part of the measure.

In addition, the House Democratic leaders along with key members of the House Education and Labor and Appropriations committees agreed to request an administration study aimed at ending a major part of the impact aid program within five years.

Carter originally had asked that some $400 million in impact aid be ended for school districts where federal employees do not live on a government installation.

The House had put $405 million in its bill for that part of the impact program and House leaders resisted White House requests to cut it out.

An exchange of letters between HEW Secretary Joseph A. Califano Jr. and Rep. Carl D. Perkins (D-Ky.) and others on his committee and the Appropriations panel sealed the deal on the bill.

It is understood House Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.) also assured administration leaders that he would work to have the final bill that goes to the White House close to the House Labor-HEW figures.

That may prove to be a difficult task. The Senate Appropriations subcommittee that handles the Labor-HEW money bill has drafted a version that adds some $764 million to both the Labor and HEW portions of the House bill.

The Senate subcommittee, for example, approved $133 million more for the National Institutes of Health than the House did, including $88 million for the National Cancer Institute.

Under yesterday's agreement with the White House, the House Democratic leaders have agreed to oppose an expected amendment by Rep. Silvio O. Conte (R-Mass.) to raise the House figure by $40.1 million.

In all, the Senate bill added over $400 million to Labor programs and over $300 million to health above the House-approved figures.

The Labor-HEW agreement followed days of negotiation that started last week on a sour note.

Office of Management and Budget Director Bert Lance met with O'Neill and others and recommended a reduced package for the bill. It was rejected, reportedly even before Lance could detail what he wanted.

On Monday, Califano, after meeting with the President, met with O'Neill and proposed cuts in impact aid, student aid and in health professional programs where money goes to aid doctor and nurse training.

Califano, too, was turned down flatly. He, however, sought some compromise and out of those discussions, the idea of agreement to cut impact aid emerged.

House leaders and many in the Senate approve the thrust of the Carter administration in cutting programs, one source said yesterday, "but the question is how to do it responsibly."

The legislative approach contined in the agreement "doesn't pull the rug out from under anyone," he said.