The United States and Cuba will reactivate the far-ranging 1984 migration agreement that called for Cuba to take back about 2,500 "undesirables" who came to Florida in the 1980 Mariel boat lift and for the United States to accept more than 20,000 Cuban immigrants annually, the State Department said yesterday.

The accord, dealing with issues that long have been major irritants in U.S. relations with Cuban President Fidel Castro, originally was signed in December 1984. It stemmed from U.S. efforts to get rid of 2,746 criminals, mental defectives and other "socially unassimilable" people sent here illegally during the massive 1980 exodus of Cubans and from Cuba's desire to reduce its "surplus population" at a time when it was experiencing severe economic difficulties.

However, Castro angrily suspended the agreement five months later when the Reagan administration opened Radio Marti, a U.S.-controlled, Spanish-language station whose broadcasts of news, commentary and entertainment are intended as a "surrogate" for Cuba's communist-controlled media.

Last year, Cuba indicated it might be willing to drop its insistence that Radio Marti be dismantled and settle instead for an agreement permitting it to beam propaganda broadcasts to the United States on an AM radio frequency. However, subsequent talks in Mexico City broke down when Cuba made demands that the United States contended would cause major disruptions in broadcasting by American stations.

State Department officials said yesterday that, at Cuba's request, new talks were held secretly this week in Mexico City between Michael G. Kozak, the department's deputy legal adviser, and Ricardo Alarcon, Cuba's deputy foreign minister. They resulted in what department spokesman Charles E. Redman described as a decision "to resume implementation of the 1984 migration agreement in all of its aspects immediately." In addition, Redman said negotiations will continue on finding "a mutually acceptable arrangement" for enabling Cuba to make medium-band broadcasts to this country.

The problem of the undesirables arose in 1980 when thousands of Cubans, driven by economic hardship, left their island homes from the port of Mariel on a fleet of small vessels sent by relatives and friends in Florida. The Castro government, in a gesture of defiance toward the United States, emptied many of its jails and mental hospitals and put the inmates on boats convoying people out of Mariel.

Those with criminal records and serious mental disorders put heavy strains on police and welfare resources in Miami and other Florida cities and led to demands by local authorities that the federal government send them back. Redman said yesterday that of 2,746 people who were declared ineligible to enter this country legally, 201 were returned to Cuba in early 1985 before the agreement was suspended.

In regard to the roughly 2,500 still here, he said: "Renewed implementation means that Cuba will once again accept the return of those individuals who have committed serious, nonpolitical crimes in Cuba or the United States or who suffer from serious mental disorders."

The other part of the agreement calls for permitting annual emigration here of 20,000 Cubans other than those with close relatives already in this country. It also establishes special categories for political prisoners that could affect about 3,000 others and for immediate relatives of U.S. citizens. The precise number of Cubans that might come here as a result is not clear, but some U.S. officials said the total number admitted under the three categories is likely to be between 25,000 and 30,000.

The reasons for Cuba's willingness to break the 2 1/2-year impasse also were unclear, but U.S. officials noted that Castro always has liked having the "safety valve" of being able to export to the United States those Cubans who have become restive at the political and economic hardships stemming from the island's communist system.