Miguel de la Madrid, 77, the former Mexican president who was credited with saving his country from economic collapse in the 1980s when he introduced free-market policies, a historic decision that altered the course of Mexican politics and helped lead to the enactment of NAFTA, died April 1 in Mexico City.

His death, of undisclosed causes, was confirmed to the Associated Press by his longtime secretary, Delia Amparo Gonzalez. Mr. de la Madrid had been hospitalized since December for respiratory ailments.

During his six years as president, from 1982 to 1988, Mr. de la Madrid led Mexico through a series of severe crises. He had inherited an economic meltdown that sent inflation rates higher than 100 percent. In September 1985, Mexico City was hit by an earthquake that killed more than 9,000 people.

Mr. de la Madrid had extensive experience in government finance, but he had never held elected office and had no background in the management of such a disaster. He was lambasted for appearing to be aloof in the days after the earthquake and for initially turning down international aid.

Combined with the country’s ongoing financial troubles, those events cost Mr. de la Madrid much of the popularity and hopefulness he enjoyed when he took office.

But he left the country profoundly changed. Since 1929, Mexico had been controlled by the left-leaning Institutional Revolutionary Party. As one of that group’s more conservative members, Mr. de la Madrid began pushing the country to the political center, particularly on economic issues.

The rightward movement culminated in 2000, when businessman Vicente Fox, a member of the National Action Party, won the presidency. Felipe Calderon, the current Mexican president, is also a member of PAN.

In foreign affairs, Mr. de la Madrid’s economic policies sparked a fundamental shift in Mexico’s relationship with the United States. (He was reported to be the first Mexican president who spoke fluent English and, with a graduate degree from Harvard University, the first who had studied in the United States.)

Mr. de la Madrid signed international free-trade treaties that helped lead to the adoption in 1994 of the North American Free Trade Agreement between the United States, Mexico and Canada. Known as NAFTA, it is regarded as one of the world’s most significant agreements of its kind.

The trade agreements were part of Mr. de la Madrid’s overall response to the financial crisis that had crippled Mexico in the years before he came to power. His predecessor, Jose Lopez Portillo, was widely criticized for overspending during the 1970s, when Mexico was raking in profits from newly discovered oil fields.

When oil prices fell, inflation and unemployment soared. The country owed a foreign debt of almost $100 billion — one of the largest in Latin America.

In response to the crisis, Mr. de la Madrid sold nearly two-thirds of state-owned Mexican companies after he took office.

He also raised taxes, ended subsidies on products such as tortillas, slashed government spending and increased interest rates.

Those policies put Mr. de la Madrid in agreement with President Ronald Reagan, with whom he had several diplomatic visits. But they differed on Central American questions, especially on the issue of Nicaragua.

Mr. de la Madrid’s government was viewed as an influential supporter of the leftist Sandinista government in Nicaragua. The Reagan administration later became embroiled in the Iran-contra scandal, in which U.S. officials secretly sold arms to Iran and then channeled some of the profits to Nicaraguan rebels known as contras.

Mr. de la Madrid had campaigned on a promise of what he called “moral renovation” — a promise to end the historic corruption in Mexican government. Under his leadership, the former director of the state oil company was indicted on fraud charges. Mr. de la Madrid also ended a secret police unit that used torture practices and secret jails.

Mr. de la Madrid’s administration was credited with reducing corruption, but the problem persisted.

By the time his presidency ended in 1988, his opponents had cultivated a strong candidate, the leftist Cuauhtemoc Cardenas. Cardenas lost to Mr. de la Madrid’s hand-picked successor, Carlos Salinas de Gortari, in an election that was tainted by suspicions of irregularity. Years later, Mr. de la Madrid wrote a memoir that strongly suggested that the election had been rigged.

After his administration, Mr. de la Madrid led a state publishing company.

Miguel de la Madrid Hurtado was born Dec. 12, 1934, in Colima, in western Mexico. His father, a lawyer who had represented peasants in legal battles with landowners, was slain when Mr. de la Madrid was 2.

He received a law degree in 1957 from the National Autonomous University in Mexico City, where one of his professors was Lopez Portillo, the future president. After working as a lawyer with the National Bank of Foreign Commerce and the Mexican central bank, he received a master’s degree in public administration in 1965 from Harvard. One of his professors was economist John Kenneth Galbraith.

Mr. de la Madrid worked briefly at the national oil monopoly but otherwise pursued a career in government finance, earning a reputation as one of his generation’s brightest technocrats.

In 1979, he became Lopez Portillo’s secretary of planning and budget. The job put him in the inner circle of financial advisers and helped groom him for the presidency.

Survivors include his wife, Paloma Cordero Tapia; five children; and several grandchildren.

Mr. de la Madrid was known as “Hamlet” for his introspective leadership style. “I took a country with great problems,” he remarked upon leaving office in 1988, “and leave it with problems.”