To bolster the fortunes of his leftist Party of Democratic Revolution and to further his own dream of becoming the country’s president in 2012, Mr. Ebrard has pushed to legalize abortion and gay civil unions in the capital and crack down on illegal street vendors and unlicensed taxi operators, who have long been associated with crowds and crime. His plan to expand subway and bus service is ambitious and popular.

Image Mexico Citys government is offering poor men 60 and over free Viagra. Everyone has the right to be happy, the mayor said. Credit... David Rochkind for The New York Times

In announcing the erectile dysfunction program in November, Mr. Ebrard, 49, portrayed it as a way of bringing smiles to the faces of those who have reached the tercera edad, or third age, as Mexicans call the golden years.

“Everyone has the right to be happy,” the mayor said, noting that many of the poorest elderly people do not qualify for employer-based health plans and have been abandoned by their families. “They don’t have medical services, and a society that doesn’t care for its senior citizens has no dignity.”

An estimated half of Mexican men over the age of 40 experience difficulties achieving erections, said Dr. Irán Roldán, a specialist in geriatrics who helps run the new program at Mexico City’s Department of Public Health. But the subject has not been one that many men have felt comfortable talking about before.

Getting men into public clinics with the promise of free erectile medicine, Dr. Roldán said, could help them get treatment for other related health problems, like diabetes, hypertension, obesity and depression. “This is a public health problem,” she said.

So far, huge crowds have not turned out for the free Viagra, Levitra or Cialis, which are the three tablets being offered. Fewer than 100 inquiries have been made at health clinics and only about a dozen or so men whose erectile dysfunction has been diagnosed have begun the process to get the pills, health officials say. They range in age from their early 60s to 82.