Ed Koch was one of New York’s three great mayors in the 20th century, joining LaGuardia and Giuliani in that hallowed circle. Each faced different problems with unique style, but all turned the city away from disaster and toward prosperity.

That Koch departs in an election year, accompanied by an outpouring of praise and gratitude, is his final gift to the city he loved. The current crop of candidates for City Hall now has before them clear lessons on how he achieved greatness. If Gotham is lucky, one of them will also rise to the occasion.

In Koch’s case, the key was courage. The courage to confront the big problems, even when it meant breaking with some longtime supporters.

A liberal congressman from the East Side, Koch first tried for City Hall in 1973, quitting after seven weeks when he couldn’t raise money or support. He told a reporter, “That’s the last mayoral race I’m ever going to make.”

But as red ink swamped the city, Koch realized that Mayor Abe Beame wasn’t up to the task. Koch would run again in 1977.

This time, he didn’t dance around the edges, vowing to confront “the threat of bankruptcy, the loss of more and more jobs and the steadily increasing crime rates.” He called Beame, a fellow Democrat, “incompetent” and said Abe “couldn’t run a candy store.”

Koch’s team, led by the brilliant David Garth, was smart enough to let Koch be Koch — up to a point.

TV ads, some showcasing his puckish humor, were crafted to identify his name with a fresh approach.

All that is pretty standard, but the key was Koch’s willingness to buck party orthodoxy. Among outer-borough voters, especially those dismissed as “white ethnics,” most Dems were seen as too liberal and too Manhattan.

Koch was fierce in his determination to overcome that image with populist, common-sense ideas. He knew that success was possible only if his policies matched the problems and the mood of voters.

His election was just the start of his challenge — now he had to actually do something. His stroke of brilliance was to introduce a new word to New Yorkers: No.

No, no, no — we’re not going to spend money we don’t have. No, we’re not going to let the unions bring us to our knees.

No, it’s not OK to litter and loot and commit crimes and have prostitutes take over Times Square.

Koch became Dr. No with a shtick that was brash and infectious. He made it cool to say no.

Most important, he meant it and soon everybody knew he meant it. Those who tested his seriousness did so only once.

Koch did not pretend to be an expert on municipal bonds, housing or anything else. Instead, he was the leader of a team and, once a solution was settled on, used the bully pulpit, the camera and the megaphone to make it happen. He was relentless.

He was also lucky, but mostly he made his luck with courage and pluck. And there was another ingredient to his greatness: He loved the job.

Never underestimate the power of joy and a few laughs to help make the medicine go down.

Andy’s blackboard $$ bungle

Here’s a quiz: If you were offered $100 to lose five pounds but failed, would you deserve the money if you rigged the scales to pretend you lost the weight?

Of course not. Why, then, does Gov. Cuomo persist in demanding that the city and the union reach a deal, any deal, on teacher evaluations?

Like phony weight loss, Cuomo’s demand confuses appearances with substance. That he put hundreds of millions of dollars on the table as an incentive only adds to the chance of a rigged outcome. He could end up paying for a fraud.

The problem begins in Washington, with the US Department of Education’s “Race to the Top” competition. New York was awarded more than $700 million for a series of “reforms,” including a rigorous teacher-evaluation law.

The Legislature passed the law, but foolishly left the terms up to individual school districts. When Mayor Bloomberg couldn’t reach a deal with the UFT, Cuomo added a deadline and a loss of $240 million in aid for failing to meet it.

Bloomberg, to his credit, resisted the bait when the union demanded onerous terms, including that the deal expire after two years. That sunset provision could wipe out any negative grades for teachers, meaning they couldn’t be fired. Not incidentally, many districts around the state accepted sunset clauses, so they’ll get money but probably not reform.

Yet Cuomo, furious at the city’s “failure,” demands a deal without also demanding rigorous evaluations, saying he doesn’t want to punish students by withholding money. That helps the union — it doesn’t care about student performance. It is still, after all this time, pushing terms that protect even the worst teachers.

Cuomo needs to rethink his approach and aim his fury at the union bosses. If they feel the heat, maybe they’ll see the light.

‘Know’ you don’t, Chuck!

Trying to head off a stampede to the exits, the White House insists that Chuck Hagel — his disastrous Senate hearing notwithstanding — has the votes to become defense secretary.

Maybe, but Hagel’s stumbling and incoherent statements should worry President Obama.

Does the president really want someone who has so little knowledge and inspires so little confidence running the Pentagon in a time of turmoil?

Before the hearing, I assumed Hagel would encounter sharp questioning from Republicans because of his record, but would ultimately prevail.

Most senators believe presidents are entitled to the Cabinet of their choosing, within reason.

But that is in doubt because of Hagel’s terrible performance. He appeared both obtuse and evasive. Answers that reversed past statements and votes on Iran lacked conviction, making it difficult to know what he truly believes.

When he volunteered that “there are a lot of things I don’t know about” and “it doesn’t matter what I think,” he seemed worse than ignorant. He looked content to be a cipher, a man who does nothing until his phone rings with orders from the Oval Office.

That’s not good enough for the person charged with leading our armed forces. The continuing combat in Afghanistan, the rise of al Qaeda in Africa and the attack on our embassy in Turkey are reminders that we remain at war, no matter that Obama says otherwise.

The main reason Obama nominated Hagel — their shared eagerness to slash the defense budget — is a bad enough idea. Incompetence could turn the slashing into a calamity.

Let Hagel find another job he doesn’t know or care about.

Defeatist ‘candidate’

Hillary Rodham Clinton, in one of her many good-bye appearances, defended her handling of the Syrian slaughter, saying: “I’ve done what was possible to do.”

As a 2016 campaign motto, that one needs work. You know, something that offers hope and change, not defeat.