A 46-year-old man was shot dead at his nieces’ baptism party in The Bronx after his family turned away a scorned ex of one of his guests, according to police and family.

Edgar Perez, 46, was shot in the back just before 3:30 a.m. on the sidewalk near Rochambeau Avenue and Bainbridge Avenue in Bedford Park, according to police.

“He was a really good guy, he never looked for any problems. I can’t believe this happened,” his 40-year-old brother, Genero Perez, told The Post.

Edgar Perez’s 26-year-old cousin, Rodolfo Rodriguez, had told the would-be gunman he couldn’t come into the party for the two tots where his ex-girlfriend was with her new man, according to the family.

“You don’t belong here,” Rodriguez told the Post he said to the man.

When the ex came back with a gun, Perez thought his 22-year-old son was involved in a fight outside the church and had gone out to break it up.

Instead he ran into the shooter.

“My uncle woke me up at 4 in the morning and said we had to go to the hospital, and when I saw my father’s cold body I…” the son, Edgar Perez, said to The Post before breaking down in tears.

EMS rushed Perez to Montefiore Medical Center, where he died.

Neighbors told The Post the church rents out its basement hall almost every weekend for raucous parties with guests stumbling out, smashing bottles and getting into fights.

Cops were searching for the gunman on Sunday night.