Brazil's Congress unanimously approved a constitutional amendment last night that restores direct presidential elections, erasing the last institutional traces of 21 years of military rule.

The package approved in Brasilia also restores universal suffrage by granting the vote to the nation's 30 million illiterates and reintroduces elections for the mayors of state capitals this November. The nation's capital will also be represented in Congress for the first time.

The package confirmed that President Jose Sarney is keeping to the promised timetable for democratization.

Taking advantage of liberalization for political groups, the Moscow-oriented Brazilian Communist Party -- outlawed since 1947 -- officially registered with the government yesterday.

Some members of Congress, showing residual distrust of office after years without power, tried to force through demands that ministers seeking reelection resign from office a year before the November 1986 congressional election. They successfully blocked any move to allow mayors of state capitals to run for reelection.

While the machinery is now in place for a presidential election, no date has been set, despite the repeated personal assertions of President Sarney that they should be in 1988. The present constitution sets his term at six years. The last direct vote for president was in 1960.

Under the terms of the elections bill sent by Sarney to the Congress, the exact length of his mandate will be fixed by a constituent assembly that will meet in early 1987 to rewrite Brazil's constitution.

The bill's effect is to undercut calls for elections this year or next to complete the transition to democracy after the improbable manner in which Sarney became Brazil's first civilian president since a coup 21 years ago.

Sarney came to power after the death of 75-year-old president-elect Tancredo Neves last month.

He had stood as Neves' running mate to guarantee his coalition victory in January's electoral college, bringing the vote of a breakaway group of deputies. Like Sarney, they previously had supported the military government, and some opposition deputies would not forgive the changing of sides.

Even during Neves' state funeral ceremonies there was reportedly intense discussion among Neves' chief political backers, all of them potential candidates, about elections this year or in 1986.

Sarney said he had "neither requested nor desired the office," and at first did nothing to quell speculation about a two-year term.

But senior military figures warned publicly against reducing Sarney's mandate below four years, which had been agreed upon with Neves as a means of containing the far left during the delicate transition period.

Much has changed in Brazilian politics since troops ringed the Congress just one year ago, ensuring rejection of a constitutional amendment like that drafted by Sarney and approved yesterday.

A year ago, Sarney warned that direct elections being demanded by the left-of-center Party of the Brazilian Democratic Movement would destabilize the military-backed government of Gen. Joao Figueiredo that his Social Democratic Party supported.

Finally having attained power as senior members of the ruling coalition, the Party of the Brazilian Democratic Movement now wants to hold off elections for as long as possible. Dante de Oliveira, the left-wing deputy whose bill was rejected a year ago, now says "direct elections now would destabilize the democratic process."

Sarney apparently has been successful in heading off immediate elections partly because of his unexpected ability to project a personality beyond the shadow of Neves.

His commitment to social policies and a $2.5 billion spending plan also has paid off by producing political support from the left.

The administration's detailed economic policies, outlined to Congress yesterday by Finance Minister Francisco Dornelles, were condemned by a few deputies as "a monetarist repetition of old policy." But members of Congress clearly savored their newly regained authority by calling the most powerful Cabinet minister to account before he began negotiations with foreign creditors in Washington.