An unhinged man involved in a bitter child-custody battle tossed his toddler son to his death from the roof of a 52-floor building on the Upper West Side Sunday, then killed himself by jumping, law-enforcement sources said.

Dmitriy Kanarikov, 35, of Brooklyn, was supposed to drop off adorable 3-year-old Kirill with his estranged wife at 1 p.m. at the 17th Precinct station house on the East Side after a three-hour visit, as per their custody arrangement, sources said.

Instead, surveillance footage from the scene at 124 W. 60th St. shows the dad leading the child by the hand into the high-rise building at around 11:45 a.m., according to law-enforcement sources.

Kanarikov, a systems developer, then went to the top of South Park Tower with the red-haired tot and pitched the boy to his death before making his own fatal leap at around 12:05 p.m., sources said.

Kanarikov fell onto a fourth-floor landing of a John Jay College building next door and died instantly, sources said.

The child — dressed in light-blue pants, a white-and-orange striped shirt, “Cars’’ socks and a little blue rain coat — was found on a sixth-floor landing. He was rushed in cardiac arrest to Roosevelt Hospital across the street, but it was hopeless, sources said.

“They were pumping his chest and working on him, and nothing” said Luis Ortiz, who was at the hospital when paramedics rushed the child in. “It was just heartbreaking . . . They tried to do the best they could.”

The child’s mother, Svetlana, “is a mess,’’ said a law-enforcement source. She told cops that her husband had previously “threatened to kill himself and then kill our child,” a source said.

Only months earlier, the couple and their son appeared to be the picture of happiness. In March, Svetlana wrote on Facebook, “I have the best husband and son in the world.” The doting parents’ posted a video on the Web site of their smiling, blue-eyed son in footie truck pajamas growling into a book, with his mom writing, “This is what happens when we do a bedtime story.’’

Another video shows the boy brushing snow off the bumper of a car as his father proudly looks on.

Heartbreaking photos from a recent trip to the beach show the boy clinging to Kanarikov’s leg with Svetlana smiling in the background.

“It looked like that kid was his world, a neighbor of Kanarikov’s parents in Brooklyn said Sunday.

“He was a serious guy. He didn’t smile much. But when he was with the kid, he always looked happy.”

Svetlana, a mathematician and violinist, and Kanarikov, who worked for the financial-services firm TIAA-CREF, were married for four years before splitting in August, sources said.

She told cops Sunday that her husband was abusive and that they had squabbled over money, sources said. At one point, both she and the child had an order of protection against Kanarikov, but that was lifted in September, sources said.

In a September Facebook posting, Kanarikov wrote, “I want to be the best dad and husband. Nothing is more important to me right now.”

Kanarikov, an immigrant from Ukraine, had a male pal who, until two months ago, lived in the Upper West Side building where the tragedy occurred and used to visit him there, sources said.

Additional reporting by Daniel Prendergast, Kenneth Garger, C.J. Sullivan and Leonard Greene