During her first visit to Egypt as secretary of state, in March 2009, Hillary Rodham Clinton was asked whether human rights violations by the Egyptian government that had been documented by the State Department would interfere with a visit to the White House by President Hosni Mubarak. It was a good question: Mubarak had not been to Washington in five years, thanks to his clashes with the Bush administration over his political repression.

"It is not in any way connected," Clinton replied. "I really consider President and Mrs. Mubarak to be friends of my family. So I hope to see him often here in Egypt and in the United States."

Thus began what may be remembered as one of the most shortsighted and wrongheaded policies the United States has ever pursued in the Middle East. Admittedly, the bar is high. But the Obama administration's embrace of Mubarak, even as the octogenarian strongman refused to allow the emergence of a moderate, middle-class-based, pro-democracy opposition, has helped bring the United States' most important Arab ally to the brink of revolution. Mass popular demonstrations have rocked the country since Tuesday; Friday, when millions of Egyptians will assemble in mosques, could be fateful.

The administration's miscalculation about Mubarak was threefold. First, it assumed that the damage done to relations by George W. Bush's "freedom agenda" was a mistake that needed to be repaired. In fact, Bush's push for political liberalization was widely viewed, in Egypt and in the region, as the saving grace of an otherwise bad administration.

Second, the Obama administration's Middle East experts concluded that there was no chance of serious reform - much less revolution - under Mubarak. So they plotted at playing a "long game" of slowly nurturing grass-roots movements and promoting civil society, in preparation for the day when Egypt might be ready for real reform. In this they badly underestimated the secular opposition that was rapidly growing in the blogosphere and that months ago began rallying behind former U.N. nuclear director Mohamed ElBaradei.

Third, as an emboldened Mubarak stepped up repression, staged a blatantly rigged parliamentary election in November and began laying the groundwork to present himself for "reelection" this year, the administration chose to mute its criticism. Bland, carefully balanced statements were issued by second- and third-level spokesmen, while Clinton and Obama - who regularly ripped Israeli Prime Minister Binyamin Netanyahu - remained silent.

That policy continued until Tuesday, when - disastrously - Clinton called Mubarak's government "stable" and claimed it was responding to "the legitimate needs and interests of the Egyptian people." Hours later, riot police attacked the thousands of demonstrators who had gathered in Cairo's Tahrir Square. Rightly or wrongly, Egyptian opposition activists now say, Clinton and the United States are being blamed in popular opinion for that crackdown. "She is seen as having given Mubarak the green light," one told me.

Since Tuesday the administration has been frantically trying to catch up with events and at last has begun to adjust its policy. On Wednesday, Clinton appeared before reporters to say, "We support the universal rights of the Egyptian people, including the rights to freedom of expression, association and assembly." The White House press secretary suddenly declined to endorse Mubarak, and administration briefers assured reporters that Obama had supported the reform cause all along.

Egyptians are not so easily spun, nor are they satisfied with the administration's new stance. "This administration has been at best lukewarm towards our cause of democracy," Saad Eddin Ibrahim, one of the most respected Egyptian opposition leaders, told me Thursday.

"Clinton's statement on Tuesday reflected what the policy has been for two years," Ibrahim said. "The second statement was a bit more balanced. But it is still not balanced enough for our taste. What we hope for is explicit support for the demands that are being put forward by the people in the streets."

Those demands are coherent and eminently reasonable: Mubarak should step down and be replaced by a transitional government, headed by ElBaradei and including representatives of all pro-democracy forces. That government could then spend six months to a year rewriting the constitution, allowing political parties to freely organize and preparing for genuinely democratic elections. Given time to establish themselves, secular forces backed by Egypt's growing middle class are likely to rise to the top in those elections - not the Islamists that Mubarak portrays as the only alternative.

Some argue that the United States has little ability to influence Egypt. This ignores the fact that Washington continues to supply the country with billions in aid and is the primary source of weapons and hard currency for the Egyptian military - the likely arbitrator in a showdown between Mubarak and the opposition. In fact, U.S. support for a peaceful transition from Mubarak's government to a new democracy could be decisive - and it is not too late to take the right side.