Rudolph W. Giuliani will be out of office in a few weeks. I've never known quite what to make of him, and I still don't. It's doubtful that any major American city has been governed in recent times by anyone as smart, resolute, courageous, petty, vindictive and vain--all those portions served together on a single plate, no substitutions allowed.

As complex as Rudy Giuliani's personality and legacy may be, however, he will leave office with one image seared into the consciousness of people all over the country, even those who had never heard of him before September 11. It is the image of Giuliani striding down the streets of lower Manhattan that morning, dodging the debris from the World Trade Center, issuing crisp orders by mobile phone, calm and decisive in the worst moments of crisis, offering a textbook demonstration of what public leadership is supposed to be.

As a result of his actions then, and his dramatic affirmation of the city's values in the days after that, Giuliani leaves office a civic hero, so popular that his last-minute endorsement of Michael Bloomberg generated an upset victory for the Democrat-turned-Republican who will be his successor. The irony in all this is considerable.

Had the terrorists never struck, Giuliani would be returning to private life with a record of genuine accomplishment. The reduction in New York's crime rate and the reawakening of life on its streets in the 1990s paralleled the civic improvements all over the country during that time, but the scope far exceeded what was happening anywhere else. There were years when the decline in New York's violent crimes represented a substantial proportion of the total decline in the United States. Moreover, it was something that few New Yorkers ever expected to see in their lifetimes. Giuliani found New York dangerous and left it more or less safe.

And yet, as recently as three months ago, it wasn't the dramatic improvement in their quality of life that New Yorkers thought of first when they thought about Giuliani. It was the personal pettiness of his regime--the quarrels with other officials and units of government, the feuds with the press, the embarrassing publicity surrounding his marriage and extramarital affair.

Giuliani was four months away from leaving office with the grudging respect of his constituents but with scarcely any affection from them at all. Now he has both. It took a crisis to do that.

For some reason, perhaps having to do with the intensity of life in America's biggest city, or the omnipresence of the TV cameras, or the sheer difficulty of governing the place, crisis has a way of defining mayors of New York, more than it does the mayors of other big cities.

Sometimes this works against them; sometimes it works in their favor. The late John V. Lindsay had his moment-of-crisis glory. Unlike Giuliani's, however, it came at the beginning of his administration, when Harlem exploded in riot and looting during the mid-1960s. In the midst of the sirens and flashing lights and confusion in the streets, there was the youthful mayor--comforting the injured, appealing for calm, willing to risk his personal safety and unflappable in the most trying circumstances.

Lindsay will not go down in history as one of New York's more successful mayors; by and large, his ambitious social-policy crusades created more problems than they solved. But for all the enemies he made, the memory of Lindsay's courage that first summer has proven surprisingly powerful and enduring. When he died last year, at the age of 79, those dramatic images of Lindsay the urban peacemaker came quickly to the minds of many New Yorkers, even those who considered him less than a hero overall. Crisis was kind to Lindsay's reputation, as it will be kind to Giuliani's.

It was unkind to the reputation of David Dinkins, the mayor whom Giuliani unseated in 1993. Dinkins, too, will be forever associated with a moment of crisis, the one that occurred on the streets of Crown Heights, in Brooklyn, when the accidental death of a black child hit by a vehicle in a Hasidic motorcade led to three days of violence against the neighborhood's Jewish residents. Dinkins did nothing to stop the violence, was unwilling to denounce it and seemed reluctant even to acknowledge that it was taking place. His inaction in that situation came to be broadly perceived less as a case of political caution than as a failure of character.

Not all of New York's career-defining mayoral crises occur on the streets. Abraham D. Beame, the man who succeeded Lindsay in 1973, failed badly at the decisive moment when the city's economic future appeared to be on the line. As New York teetered toward bankruptcy in 1974 and '75, Beame appeared timid, indecisive, overmatched by the sheer scope of the problem. This may be unfair--it can be argued that the problem had to be solved from the outside: No one within the city's political structure could muster the influence to deal with the mounting debt. But, fair or not, Beame's four-year tenure is remembered by the vast majority of New Yorkers for only one thing: his inability to handle a crisis.

In fact, of the five mayors who have served in New York's city hall over the past 35 years, only one--Edward I. Koch, whose tenure was the longest, lasting from 1977 through 1989--has managed to escape being judged by his behavior in a crisis situation of some sort.

The Koch era generated its share of urban tension and excitement, as all eras do in New York, but there was no September 11, no threat of bankruptcy, no racial incident of the magnitude of Crown Heights. Koch came into office as a recession was ending and left as the prosperity of the 1980s was winding down. Compared with Lindsay and Beame before him and Dinkins and Giuliani after him, Koch was mayor in relatively peaceful times. And except for Giuliani in these past few months, Koch was easily the most popular of the five. Smart, genial, garrulous, politically astute, demagogic at times but open to compromise--he managed to sustain his goodwill among most of the electorate, even though many of the city's most serious chronic problems, such as its crime rate and welfare caseload, experienced no noticeable improvement under his leadership.

Not only did Koch face no situation of the magnitude of September 11, it's almost impossible to picture him in such a situation. Dashing out of collapsing buildings, barking out orders and rallying the frightened populace are roles in which Koch would have seemed absurdly miscast. He lacked the fundamental posture of seriousness for it--the gravitas, if that term has not become too much of a cliche.

All of this is a long-winded way of saying something that most of us instinctively realize: There are leaders for times of crisis and leaders for calmer times. You can hope to have the right one available at the right moment, but since crises are not predictable, there's no way to luck out every time.

And leaders who are natural crisis commanders can flounder unimpressively when there isn't anything very stirring available to do. That's true, of course, on stages much larger than the one New York mayors perform on.

Winston Churchill is Exhibit A on this subject. He was an unsuccessful and unpopular parliamentary leader in Britain during the 1920s and an embittered political outcast in the 1930s, but he was the savior of his country in World War II. In the summer of 1945, just as the war ended, British voters threw him out of office. That surprising result has often been pictured as an act of inexcusable ingratitude by an electorate that didn't appreciate what Churchill had done for them. It might also be argued, however, that the voters understood the situation perfectly well. They knew that Churchill was indispensable as a wartime leader. They weren't so sure whether he was the right man to manage the peace.

But voters don't often get the opportunity to orchestrate their cycles of leadership quite so purposefully. Most of the time, they choose leaders based more on the period they have just been through than on the one that may lie just ahead. And they create some seemingly awkward mismatches.

The United States found itself under the leadership of Harry Truman, a folksy, unprepossessing machine politician from Missouri as it concluded World War II, entered the nuclear era and slogged through three years of the Korean War. Then it chose a military man, Dwight Eisenhower, to preside over the most tranquil decade of the century.

For most of the 1990s, another period of calm and prosperity, we were led by the intense, impulsive Bill Clinton, a president with considerable powers of eloquence, drawn instinctively to excitement and action, eager to prove himself in crisis situations, and somewhat bored when they did not occur, which for most of his tenure they did not. Now we are governed by a friendly, easy-going president, passive by nature, not too ambitious and not very articulate, seemingly suited far better to peace and prosperity than to war and crisis.

If these are mismatches, they are nobody's fault. The best one can say about them is that they often work out surprisingly well. A half- century after the fact, Truman is judged to have been a capable leader both in war and in peace. And Eisenhower has come to symbolize benign, fatherly stewardship in an era of bland contentment. George W. Bush may turn out to be an effective leader in a time of crisis, even though few could have visualized him in such a role a year ago.

For much of his mayoralty in New York, Rudy Giuliani seemed a little miscast himself, so eager to lead the city in crises that he practically created them through his own belligerence where they would not have occurred otherwise. Then, however, a real crisis occurred, and he was the right leader in the right place at the right time. He will be remembered more for that than for anything else he has done during two terms in power.