WASHINGTON (AP) _ Congress handed President Reagan a major domestic spending defeat Wednesday as the Senate joined the House in overwhelmingly overriding his veto of the $20 billion clean water legislation.

The popular anti-pollution measure, criticized by Reagan as too costly in times of huge budget deficits, became law on an 86-14 Senate override vote, with 32 Republicans joining 54 Democrats in shooting down the veto.

The action, long predicted by the bill's supporters, came a day after the House cast a 401-26 override vote in what Reagan called ''the first great battle of the (budget) deficit in the 100th Congress.''

The fight, however, was a mismatch as Republicans on both sides of the Capitol joined with Democrats to defeat a White House that did little work to muster the one-third margin needed to save the veto.

''The president's decision to veto ... was a serious mistake,'' said one of the new law's chief architects, Sen. John Chafee, R-R.I. ''I am saddened that the president missed an opportunity to join the Congress in taking an important step toward meeting our common goals of assuring cleaner lakes, rivers and streams.''

Reagan, who on Tuesday urged GOP lawmakers to close ranks behind him, had few supporters during the House and Senate debates.

Senate Minority Leader Bob Dole, R-Kan., made no ringing pleas for party unity. Instead, he conceded defeat before the vote and said quietly, ''this is an opportunity to go on record for deficit reduction.''

After the vote, Chafee and Sens. George Mitchell, D-Maine, and Robert Stafford, R-Vt., said they did not think the loss on the clean water bill means that Reagan faces automatic overrides in the new Democratic-controlle d Congress.

''This was a unique set of facts,'' Mitchell said. ''But no matter what we say here, this will be widely read throughout the United States as a weakening of the presidency because of the Iran (arms) matter. But that's a bum rap.''

Reacting to the Senate's vote, White House spokesman Albert R. Brashear said: ''We are disappointed. The president's position is clear. However, the Senate has spoken.''

In six years, Reagan has vetoed 61 bills and has been overridden seven times.

It was another case of a president being beaten when opposing Congress on a major water-quality issue. It happened to President Nixon in 1972 when Congress overrode his veto of the bill creating the clean-water program, a law that became one of the nation's most successful anti-pollution efforts.

The new law reauthorizes and strenthens the basic clean-water law, with $18 million in aid earmarked for states through 1994 to build sewage and wastewater treatment facilities.

Reagan, saying the bill was ''loaded with waste and larded with pork,'' tried unsuccessfully to interest Congress in cutting the state assistance to $12 billion.

But supporters of new law said that even at $18 billion, states will be left far short of the $108 billion the Environmental Protection Agency estimates must be spent by 2000 to reach the basic law's goal of rendering U.S. waterways fishable and swimmable.

Lawmakers also said the new law achieves one of Reagan's basic water- quality policy goals: ending federal aid to the states in the 1990s.

Of the other $2 billion in the plan, there is $400 million to launch the first national attack on the stormwater runoff from streets, mines and farms that is said to be responsible for up to half the water pollution in America.

Other major features are a focusing of attention on large waterways such as the Great Lakes; closing a loophole that allows the dumping of some industrial waste into sewers; and directing special efforts against toxic hot spots that have resisted traditional abatement methods.

Reagan's veto of the legislation last Friday was his second rejection of the package in less than three months. In November, he pocket vetoed an identical 1986 bill, meaning he rejected it after the past Congress had adjourned and thus was unable to cast override votes.

The bill's supporters quickly reintroduced and overwhelmingly passed the measure in the new Congress, with Republicans and Democrats alike urging Reagan to sign it this time.

How the $18 billion in assistance will be spent is up to the states, so long as they comply with project eligibility guidelines. The allocation formula is based on state needs, although Sen. Lloyd Bentsen, D-Texas, was able to get his state nearly $17 million more than it normally would receive.

There is $166 million specifically earmarked for various projects and studies in 10 states, with the biggest chunk, $100 million, for a sewage treatment plant in Boston. This item was considered a retirement present for former House Speaker Thomas P. O'Neill, D-Mass.

Asked Wednesday to point out the pork to which Reagan was referring, White House spokesman Marlin Fitzwater, who worked for eight years with water irrigation and power projects at the Interior Department, said:

''It depends on how you want to define pork, I guess. ... I think the question goes to, is the money directly related to the need and is it effectively being spent. And our feeling was ... it wasn't necessary to have an $18 billion program at this point.''

Mitchell said Reagan was wrong saying the legislation was full of pork. He noted that the president's compromise legislation costing $6 billion less contained the same $166 million for special projects and studies.

Republican senators voting to sustain the veto were Dole; William Armstrong of Colorado; Thad Cochran of Mississippi; Jake Garn of Utah; Phil Gramm of Texas; Jesse Helms of North Carolina; Nancy Landon Kassebaum of Kansas; Richard Lugar of Indiana; James McClure of Idaho; Don Nickles of Oklahoma; Steve Symms of Idaho; Strom Thurmond of South Carolina; and Malcolm Wallop of Wyoming.

The lone Democrat voting for Reagan's position was James Exon of Nebraska.