Many of Hillary Clinton’s past detractors now give her fair credit for doing a good job as U.S. Secretary of State.

But even those Americans who find fault with her performance in that critical post should take offense at seeing any American diplomat subjected to the abuse Mrs. Clinton received Sunday in Egypt. And even the most optimistic fans of the Arab Spring should concede that it has generated considerable turmoil and uncertainty.

That doesn’t mean the status quo of the last half century remained a viable option for Egypt when its people took the streets to demand long-overdue change.

Yet as Secretary Clinton’s ugly experience there showed, the ongoing transformation of Egypt’s power structure presents major challenges for America and our allies.

Protesters in Alexandria hurled tomatoes and shoes at the secretary’s motorcade while repeatedly shouting “Monica” in insulting reference to her husband’s presidential sex scandal with a White House intern. Earlier, rowdy demonstrations forced a scheduled ceremony marking the opening of the U.S. Consulate in Alexandria from outside to inside.

Predictably, Secretary Clinton enjoyed a much more gracious reception Monday in Israel.

Many Egyptians retain considerable resentment against the U.S. Over many decades, under both Republican and Democratic administrations, we supported autocratic President Hosni Mubarak, who was ousted last year and sent back to prison Monday while still suffering from serious health problems.

There’s still a strong suspicion in Egypt that the U.S. will find a way to help that nation’s military reverse the results of last month’s presidential election, won by Muslim Brotherhood candidate Mohamed Morsi.

However, Mrs. Clinton met with the new president Saturday in Cairo and encouraged him to exert the “full authority” of his office. She also said the politically active military should “return to a purely national security role.”

Then, during the consulate ceremony Sunday in Alexandria, the secretary reiterated America’s backing of Egypt’s advance into democracy:

“I want to be clear that the United States is not in the business, in Egypt, of choosing winners and losers, even if we could, which, of course, we cannot.”

Sunday’s friendly tone, however, was marred by the spectacle of riot police struggling to hold back protestors. Though no serious casualties were reported, an Egyptian official was hit in the face with a tomato.

And while the general notion of Egyptians finally getting to choose their leaders sounds welcome, the specific outcome of an Islamist becoming president appears increasingly ominous.

President Morsi has so far expressed reassuring themes about fostering conciliation with other nations, including maintaining the historic 1978 Camp David peace agreement with Israel. He also has vowed to promote consensus solutions with his political opposition in Egypt.

Then again, Mr. Morsi was elected only a month ago.

Despite that rudeness in Alexandria, Secretary Clinton delivered a worthy message to the Egyptian people.

But balancing democracy with stability will be a difficult challenge for Egypt.

And balancing our interests with Egypt’s will be a crucial test for the United States as the Arab Spring’s potential benefits — and hazards — continue to emerge.