A man shot himself to death in his car on the Upper East Side moments after beating up his ex-girlfriend Wednesday, police said.

The 33-year-old woman was left badly bleeding from the assault inside 539 E. 78th St. at about 9:30 p.m., witnesses and cops said.

The ex-boyfriend then walked outside, got into a car, and shot himself in the head, police said.

“I heard her screaming, wailing,” one building resident said. “There’s blood all in the hallway. She was like dripping blood, she was hurt bad.”

The woman was taken to New York-Presbyterian Hospital.