President Reagan yielded to Congress yesterday and signed legislation designed to prevent him from cutting federal loans and grants to nearly 2 million poor and middle-class students under the two biggest and costliest college aid programs.

The president had tried all year to eliminate some or all federal aid to more than a third of the 5.5 million students who are now eligible for the loans and grants. But he agreed to sign the bill with only minor changes when it became clear that Congress would not cut the politically popular programs in an election year.

Reagan said, however, that he would not obey a provision allowing either house of Congress to veto more-stringent eligibility rules the administration might submit in the future.

Attacking the provision as unconstitutional, Reagan said "one house of Congress cannot bind the executive branch by a simple resolution alone."

Reagan had proposed substantial cutbacks in the so-called Pell grants for needy students and guaranteed student loans for middle-income students, two of the fastest-growing programs in the federal budget. But Congress, angered by administration delays in carrying out the current program, drafted this bill to ensure that about the same number of students are eligible for federal aid in the 1983-84 school year, at a cost of more than $6 billion.

The measure also restores student aid immediately for up to 50,000 veterans who were abruptly excluded last year.

After making some initial cutbacks last year, Congress has proved increasingly resistant to trimming one of the few entitlement programs that serve the middle class. That reluctance grew even stronger as the election neared.

The administration repeatedly has failed to meet congressional deadlines for submitting the detailed rules that govern how many students are eligible for federal aid and how much their parents must contribute. Since colleges begin planning for these aid programs a year or more in advance, congressional critics say, the delays have caused serious problems for deans and students alike.

"The whole purpose of this bill is to tie the hands of the administration so it cannot continue to disrupt these programs," a congressional staff member said.

"My instinct is that, by delaying, the administration figures they will discourage some kids from going to college and would save some money," said Rep. Paul Simon (D-Ill.), chairman of a House education subcommittee. He said that Reagan's proposed cutbacks "would have been devastating," but that the president signed the bill because "he read the tea leaves in the House and Senate.... His veto would have been overwhelmingly overridden."

The measure also prolongs a long-running dispute over the "legislative veto," a device by which either house of Congress has overturned a variety of federal regulations. Reagan supported the legislative veto during his election campaign, but now opposes it as an infringement on the executive branch.

The new bill requires the Education Department by next April to submit new eligibility rules for college aid, which then can be vetoed by either chamber. If the department again fails to produce the rules on time, Congress would simply extend the current standards into the 1984-85 school year, with an adjustment for inflation.

Reagan, however, said Attorney General William French Smith has advised him that this "unconstitutionally encroaches on the principle of the separation of powers," and that the secretary of education "will implement this law in a manner consistent with the Constitution."

But Simon said that Reagan "has to abide by the law until the courts knock it out."

The bill involves no appropriations. But it means that about 2 million students next year will continue to be eligible for Pell grants up to a maximum of $1,800 a year.

Based on a complex formula, the grants are available to families with up to $25,000 in "discretionary" income, who then must pay up to a quarter of a student's college costs. Reagan wanted to lower the income ceiling to $18,000 and nearly double a family's required contribution; critics said this would exclude all but the poorest families.

About 3.5 million students from families earning under $30,000 will be eligible for guaranteed loans, which they would repay at 9 percent interest. Families earning over $30,000 are subject to a "needs test" that gradually reduces the size of their loans.

Reagan had proposed to require a needs test for all applicants, to double the "loan origination" fee to 10 percent and to bar about 600,000 graduate students from the program.

The bill reversed an earlier White House change by restoring Pell grants to veterans, who will have less of their GI Bill benefits counted as income. But Reagan said he was pleased with another provision that no longer allows the government to consolidate or stretch out payments on student loans.

The administration may renew its push for further cutbacks when Congress votes to finance these programs after the election. White House spokesman Anson Franklin said Reagan hoped that "some of the appropriations will be more in line with what we'd like to see."

Sen. Claiborne Pell (D-R.I.), for whom the grants are named, said the bill "was absolutely essential to eliminate once and for all the confusion and uncertainty" surrounding the aid rules. Most Republicans, led by Sen. Robert T. Stafford of Vermont, also supported the measure, which was aided by a strong lobbying effort by education groups.

In another development, Reagan signed a three-year extension of the Endangered Species Act, which protects rare plants and animals from the threat of construction projects. The act is best known for holding up the Tellico Dam in Tennessee because of the danger it posed to the tiny snail darter.

More than 220 animals and 61 plants have been placed on the endangered list.