Sometimes you gotta break the rules to do the right thing.

An NYPD cop told The Post about the moment he helped an ill young woman make a prohibited right turn so she could pierce Manhattan gridlock and make it to her chemo appointment on time.

Officer Hamlet De Leon was monitoring 57th Street and 6th Avenue on Thursday — heavily congested thanks to the United Nations General Assembly — when Gabriela DeMassi, 28, and her mother got out of their car and asked the cop if there was a quicker route to Memorial Sloan Kettering Hospital.

At the rate the traffic was going, DeMassi –– who was undergoing her third round of treatments for lung cancer –– was doomed to miss her appointment.

“If I say bad, that’s an understatement. Traffic was horrific. To get to complete a block, I would take at least 45 minutes,” De Leon, 37, recalled in an interview with the Post.

For De Leon –– who has been on the force for four years –– the resolution was simple: Let her make a right turn onto 57th Street that was prohibited because of UNGA traffic changes.

“I said, ‘Get back in your car, because you are getting to your appointment,’ ” he said.

“She looked at me kind of stunned. I went to the traffic agent who was instructed to not allow cars to make right turns — and I said ‘I’m not asking you, I’m telling you that car will be making a right turn and I will be with that car,'” DeLeon recalled.

In their Mercedes-Benz, DeMassi and both of her parents followed De Leon, who led them away from the congestion and towards the hospital.

“I wasn’t thinking whether or not I was disobeying the order. It was a life. And in my eyes, that takes precedence over anything. I was willing to take repercussions,” De Leon said. “I said, ‘You better keep fighting, you got this!’ Then the mother started crying and I reached her hand and said, ‘Ma’am, everything is going to be alright.’ ”

DeMassi left her appointment with happy news: Her tumors did not grow.

“Something like this will touch us forever,” DeMassi wrote in an Instagram post afterward. “As if driving into NY isn’t crazy enough, we all have a bit of anxiety planning for full days of labs, meetings, tests, treatments and scan results. This group of cops that we had the pleasure of running into … should know how their help today made all the difference in our day.”

DeLeon learned about the social media post — and his Commanding Officer commended him for his work.

“I’m not going to lie, it brought tears to my eyes,” De Leon said of the post. “I didn’t do for any recognition. It was the last thing I expected. Police officers get a bad rap, but not all of us are bad. A lot of us think about the right thing to do.”