It’s not often that the United States has the obligation, or the opportunity, to completely remake its relationship with one of the world’s major nations. Usually, for better or for worse, ties are locked in by history, perpetuated by enduring elites, and defended by powerful lobbies. Even bad policies are hard to change.

Now, however, Washington has no choice but to rebuild its connection with Egypt — the most populous and historically most important Arab nation, the owner of the Suez Canal and a prime U.S. ally for more than 40 years. It is a daunting, even scary prospect for the State Department and Obama White House. But it is also offers a chance to correct some of the mistakes America has made for decades in its dealings with Arab leaders. The remake launches this week when Secretary of State Hillary Rodham Clinton visits Cairo.

The need for a revamp has been obvious for some time, but it became imperative last month when Mohammed Morsi, the candidate of the Islamist Muslim Brotherhood, won Egypt’s first free election for president. Up until then, and despite Egypt’s popular revolution last year, U.S. policy had centered on the powerful military and the succession of pharaoh-like leaders it backed. Year after year, strategic allegiance and peace with Israel was purchased with $1.5 billion in annual military and economic aid.

Now it gets complicated. For the foreseeable future, U.S. officials will have to navigate between Morsi and the Brotherhood, with their nominally democratic but fundamentally anti-Western agenda; the military, which is doing its best to block the creation of democratic institutions while preserving its lifelines with the Pentagon and Israel; and the secular democratic forces that led last year’s revolution, which are broadly pro-Western but are squeezed by both the generals and the clerics.

A successful walk along this tightrope could preserve Egypt as a core U.S. ally and peaceful neighbor of Israel while transforming it into a functional democracy — something that would make both those roles more stable. Or, Egypt could become the world’s next Pakistan, a country riven between incompetent and corrupt civilian politicians and double-dealing military commanders.

The Obama administration’s first two steps in this acrobacy managed to alienate and confuse all sides. First, in March, it waived congressional conditions on this year’s military aid that required the generals to complete a democratic transition — something that may have encouraged the military’s subsequent dismissal of the elected Congress and usurpation of the new president’s powers. Egyptian democrats felt betrayed.

But then last month the administration leaned heavily on the ruling military council to recognize Morsi’s victory in a runoff election. Lobbying by Clinton and Defense Secretary Leon Panetta may have prevented the council from handing the presidency to its favored candidate, a former prime minister. But it infuriated the generals, Egyptian Christians and some U.S. supporters of Israel, who fear the Islamists more than the old regime.

Now what? Quite understandably there’s been vigorous debate inside the administration about the best way to approach Morsi, and about how to use U.S. aid. What seems to be emerging is a cautious, step-by-step approach in which Morsi’s government would get U.S. support in obtaining economic assistance from the International Monetary Fund as well as a long-delayed debt-swap deal — provided that it follows through on promises to preserve the rights of women and religious minorities, respects democratic norms and preserves peace with Israel. In a visit to Cairo Sunday, Deputy Secretary of State William Burns sketched those terms following a meeting with Morsi during which he delivered a letter from Obama.

Burns didn’t publicly mention military aid, but the administration has been thinking about that, too. The consensus is it should be continued for now, but some officials believe it should eventually be restructured, reduced and focused on missions like counter-terrorism and border protection, rather than the purchase of expensive American hardware.

In conception, that’s not a bad plan. The challenge will be avoiding the classic pitfalls of U.S. Middle East diplomacy. One is to shower too much attention and favor on those who happen to be in power. Though the military and the Muslim Brotherhood hold the strongest cards for now, neither can be a strong or reliable partner over time. America’s real friends are Egypt’s secular democrats and its emerging middle class, who have been shoved to the sidelines but are the country’s best long-term hope.

The other big danger is that U.S. policy will be pushed back into the old ruts by Egyptian or domestic pressure. The military will resist any alteration of the aid program, or supplanting of its influence in Washington by civilian leaders. Some in Congress will demand that the administration deny aid to an Islamist government. Giving into those pressures would be the quickest way to blow this opportunity for diplomatic change — and turn Egypt into a second Pakistan.