Three of the bullets shattered Hartnett's left arm, causing severe nerve damage. Still, the five-year police veteran managed to return fire and wound the suspect, who was later arrested.
"This is a dangerous job," police Commissioner Richard Ross said. "This incident captures the essence of that. ... You never know what that next encounter will be."
Hartnett, who is recovering after several surgeries, has been praised for his generosity as well as his courage. He would buy coffee and sandwiches for homeless people, according to colleagues. He'd stop to say hello and make small talk with people on the rugged streets he patrolled.
"He was a compassionate police officer," Ross said.
Hartnett's heroism comes at a time when a string of controversial police encounters have led to protests and fueled public distrust.
On Tuesday, Cleveland police and the police union announced that six Cleveland police officers had been fired
in connection with a November 2012 car chase that ended with officers firing 137 bullets at a car, killing Timothy Russell and Malissa Williams. That incident followed deaths involving officers in Baltimore, Chicago, and Ferguson, Missouri, among others.
Still, random acts of kindness and occasional heroism among the more than 900,000 sworn officers in the United States often go unnoticed. CNN will be featuring stories of heroism by officers in the new series "Beyond the Call of Duty," which airs Fridays on "New Day" and "CNN Newsroom."
"Truly heroic work does, I hope, get the recognition it deserves: the officer who runs into a burning building to save someone, the officer who risks his or her life to save that of a civilian in a hostage situation," says David Harris, a University of Pittsburgh School of Law professor and an expert on policing.
"But the work of police officers is full of other types of good work every day: helping the good people in neighborhoods with the problems they have. Helping us all, in small ways, to have a safe and prosperous place to live. That's the everyday work that doesn't get a lot of recognition, because it's not unusual."
In his State of the Union address
this month, President Barack Obama praised ordinary Americans whose toil gets little attention or fanfare, including "the young cop walking the beat, treating everybody with respect, doing the brave, quiet work of keeping us safe."
That work, both heroic and prosaic, occurs almost daily across the country.
Take the case of James Roberts, 58, who got lost on the way to a recent job interview in New York. Roberts asked a police officer for directions.
"'You'll never make it,'" the officer told Roberts. "'Get in the car.'"
The officer left Roberts at the place of his interview.
"Good luck and God bless you," the officer said.
Roberts, who got the job after struggling for years to find one, has been looking for the officer to say thank you. A New York Police Department spokeswoman said it's unclear whether the officer worked for the city or the Port Authority police.
And just this week, NYPD officers helped a woman who was in labor along FDR Drive in the middle of the morning rush hour. Detective Michael Sharpe was on his way to traffic court when he got a radio call saying a woman was in labor "right now," the NYPD said on its Facebook page. Sharpe spotted the car on the shoulder and helped the mother bring her baby boy into the world.
In Minnesota, as temperatures dipped to subfreezing levels, State Trooper Glen Bihler bought dinner for a homeless man found lying on the shoulder of a highway near Aitkin, according to the state police Facebook page. When there wasn't room at a shelter, the trooper arranged for the man to spend the night in the lobby of the sheriff's department.
A similar story played out in San Francisco, where a homeless woman and her autistic teenage son were turned away from several shelters this month, CNN affiliate KTVU reported.
A group of police officers pooled together $400 for a hotel room and groceries for the family
"Who knows where they could've ended up," Officer Brian Kneuker told the station. "But when we got the call, our goal was -- we're not going to have them end up on the street."
In Nebraska, two police officers and a civilian, without protective gear, rescued five people from a burning home in Omaha last month, CNN affiliate WOWT reported.
After two people were safely removed from the home, one of the officers went back in when he heard screams. He rescued three disabled people.
Officer Robbie Goering-Jensen was treated at a hospital for smoke inhalation, the station reported. His partner, Officer Anthony Abboud, was treated for smoke inhalation at the scene. Abboud was working his first shift since graduating from the police academy days earlier.
In Lake Geneva, Wisconsin, officers arrived at a home that was ablaze. A mother threw her baby from the roof to an officer. The officer caught the child, who was not injured, CNN affiliate WITI reported.
William Terrill, a policing expert at Arizona State University, said acts such as these are not unusual and often are overshadowed by negative stories about police abuse and misconduct.
"Many, many times I see officers pull money out of their pocket and buy someone a coffee, buy someone a meal, take them inside and let them warm up," Terrill said.
"I've seen officers let folks in the back of their car to warm up while they're handling an incident. They see someone on the corner and they say, 'Why don't you hang out in the car while I handle this incident.' It had nothing to do with them. They're just letting them warm up."
Good policing is hard to measure through official records. An important yardstick of good police work is an officer's ability to defuse situations "with the least amount of authority or the least amount of force," Terrill said.
"An often downplayed part of good policing is the voice, the demeanor, the people skills of an officer," he said. "The idea that it's not just about the stick. It's not just about arrests."
The public has become accustomed to associating "good policing" with proactive cops who seize the most guns or make the most arrests, said Harris, the University of Pittsburgh School of Law professor and policing expert.
"Good policing or being a good cop means preventing disorder, heading off arrests, building relationships with people and communities so that problems can be addressed not just with physical courage or force or with barked orders, but with communication, cooperation and strategy," Harris said.