Congress yesterday approved landmark legislation that would forbid most employers to set a mandatory retirement age, a move that would extend equal employment protection to hundreds of thousands of elderly workers and end a national tradition of forced retirement based on age.

President Reagan, who at 75 is the nation's oldest president, is expected to sign the measure, which supporters say will give the elderly a psychological as well as an economic boost.

"Now you know in America . . . you can continue to work as long as you're willing and able," said 86-year-old Rep. Claude Pepper (D-Fla.), the oldest member of Congress and primary sponsor of the bill. "That's a great and meaningful achievement."

The Senate passed the measure by unanimous consent early yesterday morning after it was amended to provide seven-year exemptions for firefighters, police and college faculty. The amended version was approved later in the day by the House, also by unanimous consent.

A federal study projected that 200,000 workers who would otherwise have retired would remain in the work force because of the legislation.

The Congressional Budget Office estimated that the change would save the federal government $ 25 million annually by 1991 in reduced Social Security and Medicare payments.

But opponents predicted that the measure would be costly to employers, disrupting collective bargaining, pension and personnel matters and increasing the number of age-discrimination lawsuits filed by employes.

"The problem is going to get worse for employers," said Mark A. de Bernardo, an attorney with the U.S. Chamber of Commerce. "This will have a significant impact on what is already a liability crisis for employers."

The Chamber of Commerce and a handful of senators tried unsuccessfully to protect employers by adding provisions to the bill that would prohibit jury trials and limit damages in age-discrimination lawsuits.

Colleges and universities have also argued that the bill would reduce the number of teaching slots available for young faculty by protecting older, tenured professors expected to retire during the next 15 years.

"This does not in any way address the demographic problem that we face between now and the year 2000," said Sheldon Steinbach, an attorney with the American Council on Education, which had advocated a 15-year exemption for colleges and universities.

The legislation amends the Age Discrimination in Employment Act of 1967, removing a provision that allows firms to mandate retirement at age 70. That bill was amended in 1978 to raise the allowance for mandatory retirement from age 65 to 70. The bill applies to firms employing more than 20 workers and requires employers to provide health benefits for workers aged 70 and older.

Passage of the bill surprised many who had considered it dead because of strong objections to a version passed by the House last month. The legislation was revived last week by a small group of senators, led by Sens. John Heinz (R-Pa.) and Howard M. Metzenbaum (D-Ohio).

"There will be a tremendous impact," Metzenbaum said. "Literally hundreds of thousands of Americans will stand taller and breath a sigh of relief knowing there isn't hovering over them that mandatory retirement." Heinz dismissed the dire predictions made by employers. "Most employers I've talked to admit that their fears about raising the age cap from 65 to 70 were largely illusory," he said.