FORTUNE — “I’m a rookie,” Ray Kelly begins.
New York City’s top cop is sitting in a back room at the Highliner on 10th Avenue and 22nd Street, waiting for a Cuban sandwich while sipping lemonade. He’s been coming to this restaurant since 1976, when it was the Empire Diner and Kelly was a lieutenant in Manhattan’s 10th Precinct. The story he’s telling goes back a decade before that, to the night he made his first arrest.
“I’m by myself,” Kelly continues. “It’s almost four in the morning. I’m in the doorway. Two guys come down the street with a girl. She gets shot with a shotgun. She screamed and they began to run. But I had a running start. So I jumped over the girl. I knew right away the arrest was more important. I grab the guys, I get the shotgun, then proceed to put a tourniquet on her leg. She was shot with birdshot, which is lots of pellets, you know.”
Blood everywhere. The girl was screaming. But she survived, leg intact, and young patrolman Kelly earned his first police commendation. “I got both of the guys,” he says plainly, “got the gun, and helped the girl.”
Kelly’s got a classic copper’s mug — a “nineteenth-century face,” as the New Yorker once described it. Round head, small eyes, boxer’s nose, tight lips, and an unreadable aspect that cracks like pond ice into a crinkly grin whenever he’s amused. He likes a dark suit with pinstripes, well-shined shoes, a bright tie. He is not a tall man. I caught a side view of him this afternoon at headquarters. He was at the head of a long table, running a meeting of his 20-member executive team. His eyes lined up with everybody else’s but only because his seat sat a tad higher on its hydraulic lift than theirs. His toes barely brushed the floor.
Kelly may have the toughest job there is. The NYPD is the biggest police force in the country. Running it is not unlike running a midsize Fortune 500 company — except that the stakes are much, much higher. Kelly manages a $4.9 billion budget, 250 buildings, 7,000 pieces of rolling stock, and 50,000 employees, most of whom carry handguns. One of his operating units is devoted to fighting terrorism. Like a CEO, he contends with a vast and varied cast of stakeholders who scrutinize his every move, but the metrics by which his performance is measured all have to do with life and death.
New York in 2012 is averaging a little over one murder per day, on pace to record the lowest total in decades. This in a city that experienced a horrific 2,245 murders at the bloody peak of the crack epidemic in 1990, when there were a million fewer New Yorkers than there are now. Criminologists can argue about how much credit Kelly deserves for a trend whose drivers are many and complex, and whose origins precede his arrival. And critics of Kelly’s aggressive stop-and-frisk tactics can ask, “At what cost?” But no one can deny that New York City on Commissioner Kelly’s watch has become a dramatically safer place to live, work, visit, and invest. Consider this: According to an article in the British medical journal The Lancet, over the past two decades the average life expectancy in New York City has risen faster than anywhere else in the country — in part because New Yorkers today are 80% less likely to get rubbed out.
But in the world ours has become, fighting crime covers only half of Kelly’s job description. He also has to protect New York City from another terrorist attack. “We say that terrorism is theater,” Kelly says, “and this is the world’s biggest stage.” Kelly’s counterterrorism bureau, the first of its kind, is led by a veteran federal prosecutor whose prior posting was at the U.S. embassy in Moscow. It works with an NYPD intelligence division, run by the CIA’s former head of covert operations, that deploys 12 New York City cops in foreign cities. And it has a new, $100 million surveillance network, called the Domain Awareness System, that oversees wide swaths of Manhattan and the outer boroughs.
Here, too, Kelly appears to be winning. Does he deserve all the credit? Of course not. Has he trod on civil liberties along the way? Some would say so. The Associated Press won a Pulitzer Prize in 2012 for its takedown of a secret NYPD program that spied on American Muslims. And yet it’s a fact that despite what the NYPD counts as 14 tries — including a plot to bring down the Brooklyn Bridge by cutting its suspension cables — there hasn’t been a successful terrorist attack in New York City since 9/11.
“I feel totally indebted to him,” says real estate developer Mort Zuckerman. Former AIG CEO Hank Greenberg says, “I think Kelly has made life safer in the city.” Larry Silverstein credits Kelly for giving foreign investors the confidence they needed to bring “hundreds of millions of dollars — trillions over time — back to the city of New York.” Silverstein, who signed a lease on the World Trade Center in July 2001, is now rebuilding. “If people lived in fear,” he says, “this would be a fool’s effort.”
Certain powerful New Yorkers think what all that adds up to is an opportunity for Kelly, currently an independent, to run for mayor in 2013 on the Republican ticket. (Mayor Michael Bloomberg’s term expires at the end of that year.) Many of them were gathered in the ballroom at the Waldorf-Astoria on a warm night last spring for the annual fundraiser for the New York City Police Foundation, whose top-donor list includes billionaire Ira Rennert, former Revlon International (REV) chairman Paul Block, and Ivanka Trump. Ask Kelly, who is 71, if he wants the job and he always gives the same answer: “I have no plans to run for public office.” But earlier this year Kelly, or persons close to him, did reach out to potential backers. “I think he came away with a sense that there were wealthy people who would throw their support and funding behind him,” says one who was privy to those meetings.
“There’s a crew in the city that are conservative Republican businessmen that kind of come together and pick and choose a candidate if they want to get involved,” says former New York Republican state chairman Bill Powers, now a lobbyist. “Ray would attract all of those guys and ladies.” Powers has already lined up Georgette Mosbacher, the prominent Republican fundraiser, to chair Kelly’s finance committee should he decide to run. Powers has done his own polling and says the commissioner’s numbers are “spectacular. There is no doubt in my mind that he can be the next mayor of New York City.”
On the night of the day the towers fell, Ray Kelly found himself alone in a bleak Midtown hotel. A fleabag, he called it, one block from the old CNN studios at 33rd and Eighth. The network put him up there so it would have access to his expertise. For which Kelly could only be grateful because he had no place else to go. He was out of the police force at the time, working in the private sector. His apartment, across the street from the World Trade Center, was inaccessible. His wife was away on a trip, and he had determined that his grown sons were safe. From his window, Kelly could see smoke rising in the glow downtown — only three miles away, but it might as well have been 3,000. “I had no role,” he says, recalling how useless he felt. “I couldn’t go there.”
Kelly grew up on Manhattan’s Upper West Side. His dad was a milkman, and his mom was a checker at Macy’s. During college he took a part-time job as a police cadet on the telephone switchboard, because he knew he wanted to go to law school one day and he thought the department might pay for it. In the end the feds covered his law school tuition at St. John’s through the GI Bill (Kelly took time out in his twenties to lead Marines into battle in Vietnam), but by then he was hooked on “the excitement, the adrenalin” of police work. Even after he earned another law degree at NYU and a master’s in public administration from the Kennedy School at Harvard, Kelly kept his badge, rising steadily through 25 commands, all the way to commissioner in 1992 under Mayor David Dinkins.
When Dinkins lost his job two years later to Rudy Giuliani, Kelly lost his too. (Not a surprise. Every mayor wants his own commissioner. “It’s the most important appointment he makes,” says former mayor Ed Koch.) Kelly spent the next seven years far from New York: In Haiti, as director of an international police force restoring order after the return of President Jean-Bertrand Aristide, and in Washington, where he served President Clinton as undersecretary for enforcement in the Treasury Department, and later as director of the Customs Service. When Clinton left office in January 2001, Kelly came home to New York, looking for a job.
“You’re crazy,” Ace Greenberg, then CEO of Bear Stearns, told his people when they brought him the idea of making Kelly the firm’s director of security. “He’s not gonna stay here. He’s so overqualified it’s ridiculous.” But Kelly, offered a lot of money and the title of senior managing director, took the position. Then came 9/11. Two months later, Nov. 6, was Election Day. On Nov. 7, Kelly got a call from the mayor-elect, asking him to return as commissioner. “Once I thought about it,” Bloomberg says, “there was nobody else.”
One of Kelly’s own first hires was David Cohen, the CIA veteran he charged with revamping the NYPD’s intelligence division. Like Kelly, Cohen had left government work after many decades and was finally cashing in — in his case, analyzing political risks around the globe for Hank Greenberg at AIG (AIG). Kelly knew exactly how to pitch to a guy like that. “I myself had been out for a while,” Kelly says. “The job is intoxicating. People miss it. Money makes up for some of it, not all of it. I was able to get some people back into it who wanted to play in the game. The song was still in them, as someone put it.”
Terrorism was the new reality. Kelly had witnessed it twice now. The 1993 bombing of the World Trade Center, which killed six people, happened on his watch. On the night of the explosion, standing at the edge of the floodlit crater, Kelly had been assured by a supposed expert that “this building could never come down.” Kelly knew better now. And having had a taste of Washington, he understood that the burden of protecting New York from another attack was ultimately New York’s to bear.
After 9/11, Kelly had a free hand to remake the police department. Besides Cohen, he recruited a retired three-star Marine general, Frank Libutti, to create the antiterrorism bureau. He basically redrew the precinct map to include distant NYPD outposts in London, Singapore, Amman, Jordan, and eight other foreign cities, and raised private funds from the Police Foundation to cover the extra costs. “The fact that something happens overseas, you say, ‘Well, that’s not your concern,’ ” says Richard Daddario, the NYPD’s current deputy commissioner for antiterrorism. “It can become our concern. And if it becomes our concern here, it’s too late.”
Kelly authorized Operation Nexus, under which New York cops regularly visit hardware stores, self-storage facilities, scrap yards, and plastic surgeons’ offices, the goal being to touch anyone whose services a terrorist might conceivably employ. (Homeland Security does something similar, but they send letters, says Cohen: “We send detectives.”) And if you’ve spent any time in New York recently, you may well have witnessed a sudden, frightening display of force by the heavily armed Hercules unit — an unsubtle reminder to anyone who might be watching that Kelly’s NYPD stands ready to defend the city.
Kelly transformed standard police work in the city too. By the time Kelly began his second tour as commissioner, crime had been falling for more than a decade. His charge was to keep the trend moving in the right direction, but with a frozen budget after inflation and ultimately about 6,000 fewer cops. “The job is to do the job with the resources we have,” Bloomberg says he told Kelly. “Not to say, ‘If I had more resources, I could do the job.'”
Kelly got some help from a fortuitous wave of retirements. So that even as payroll was shrinking, new cops were continually joining the ranks. That let Kelly leverage New York’s diversity by hiring more blacks and Latinos, as well as native speakers of languages such as Farsi, Arabic, Urdu, Pashto, and Hindi; the NYPD has been a majority minority police force, at the patrol level, since 2006. And he assigned new cops to high-crime neighborhoods where they were needed most.
Initially, almost everybody thought Kelly was doing a great job. But the more recent scoring has been mixed. The AP series shined a light on the seamy side of the war on terrorism.
Among the surveillance targets was a Staten Island mosque that is known for publicly condemning Islamic terrorism. “We were disappointed,” says Suhail Muzaffar, the mosque’s Pakistani chairman. He worries the revelations may have led “to disenchantment among our young people.” Donna Lieberman, executive director of the New York Civil Liberties Union, is willing to admit that “Ray Kelly has one of the toughest jobs in the world. There’s no way to end crime, there’s no way to end police abuse. All you can do is harm reduction.” But lately Lieberman has taken a tougher stand against the practice of stop and frisk, the targets of which are overwhelmingly black and Latino young men. (Kelly’s counterargument begins with the fact that more than 90% of shooting victims are also black and Latino young men, and ditto for the perps.) The NYPD was also widely condemned for its treatment of some of the Occupy Wall Street protesters, especially after a videoclip of a policeman gassing a demonstrator went viral.
Kelly is unapologetic. Longtime New Yorkers may recall that the commissioner used to be a big advocate for so-called community policing — soft strategies like midnight basketball and after-school programs that aim to reduce crime by strengthening neighborhoods. “Yeah, fine,” Kelly says now, “nobody’s against that. That’s chicken soup. But in terms of getting guns off the street, we’re proactive.” Since 2002, the number of recorded stop-and-frisk incidents has grown sharply, from less than 100,000 annually to nearly 700,000. Carnegie Mellon criminologist Alfred Blumstein describes the increase as “staggering,” even while conceding “the stop and frisk was in a sense appropriately targeted.”
“Exactly,” says Kelly, who adds a staggering statistic of his own: Such stops last year netted more than 8,000 illegal weapons, including 819 guns.
At last count the NYPD was contesting four major lawsuits aimed at limiting stop and frisk. The Domain Awareness System may pose even more troubling questions. It’s a massive, networked array of public and private surveillance cameras, license-plate readers, radiation detectors, arrest records, incident reports, and facial-recognition software that the NYPD developed with Microsoft (MSFT) and is marketing to law enforcement agencies all over the world; New York City will get a 30% cut of the profits. Already it sees everything river to river in Manhattan south of Canal Street and between 30th Street and 60th Street.
When a man shot and killed a former colleague across the street from the Empire State Building in August, NYPD officers were able to link the 911 call instantly to a surveillance camera at the scene. Seconds later, all available cameras within a 500-foot radius were summoned, one of which, around the corner, caught the shooter as he pulled his weapon on police and was himself shot and killed. “It’s the most advanced system of its kind in the world,” Daddario says proudly. He credits it in this case with quickly ruling out a terrorist attack, and so preventing a massive and unnecessary police response. But how will New Yorkers feel when the rollout is complete, and nothing occurs in public in the city without the possibility, at least, that the police are watching?
One evening last summer, I accompanied Kelly to a gathering of the National Association of Black Law Enforcement Executives at a banquet hall in Howard Beach. The conversation among the officers was all about Kelly’s prospects if he decides to run. Assistant chief Gerald Nelson, patrol borough commander for Brooklyn North, told me “of course,” he would support his boss, and he had no doubt he would win: “He’s a workaholic and he’s a brilliant man. So anything he sets his mind to do, he’ll get it done.”
His age is a factor. Bloomberg would support him — he thinks he’d make “a very good mayor,” but adds, “Ray’s gotta be feeling like me. We’re both in our seventies. It gets tougher to get up in the morning.” He doesn’t have to decide right away. With the NYPD currently enjoying a job approval rating above 82%, it’s hard to imagine how he could be running a more effective campaign if he were in fact campaigning. How badly does he want it? Even his friends aren’t sure. One says he suspects the idea would never have occurred to him if it hadn’t occurred to others first. But the pressure to run is building, side by side with a shadow organization that’s just waiting for the word from Kelly.
–Reporter associate: Doris Burke
This story is from the October 29, 2012 issue of Fortune.