A schizophrenic Brooklyn man threw his four-year-old brother off their seven-story building’s roof to his death early Saturday — then walked up to a cop car and calmly confessed, police sources said.

“I just killed my brother — I took my brother up to the roof and I threw him off,” Shawn Smith, 20, allegedly told officers before leading them to where his brother’s broken body lay twisted in a trash-strewn Midwood courtyard, sources told The Post.

Shawn was charged Saturday afternoon with his brother’s murder, which happened at 2:45 a.m., minutes after he allegedly led the boy up to the roof.

He had no prior criminal record or history of violence, police sources noted.

But he recently told his family that voices in his head were ordering him to do “something bad—” though he didn’t, or couldn’t, warn anyone what that might be, police sources said.

And he’d been suicidal in the past — prompting several 911 calls in April, when he climbed up to the same roof at Nostrand Avenue, near Avenue K, and onlookers feared he might jump, the sources said.

Last admitted to Kings County Hospital in July for psychiatric treatment, Shawn had since stopped taking the medication prescribed to treat his schizophrenia, family members told cops.

“This was a chronic problem,” one police source said of Shawn’s mental illness.

Shawn and Shimron were the oldest and youngest children of Odessa Frith, who’d moved her family into the sixth-floor apartment in December from their native Guyana.

“Mom is screaming” neighbor and family friend Andrea Fergus answered when asked how Frith was holding up inside the 63rd Precinct hours after the tragedy.

“She’s got six kids,” Fergus said.

“She’s got one kid at the precinct and another one dead.”

Shimron was loved by neighbors as an active, playful little boy.

“He would ride that little bike up and down the block, up and down,” recalled a neighbor who identified himself as “D.M.,” 23.

“He was always so sweet.”

But Shawn was seen as quiet and troubled.

He would often be seen pacing the sidewalk outside their complex. He’d smoke cigarettes, and say little.

“Loco,” is how one cousin who declined to give her name put it. “Crazy in the head.”

“He doesn’t speak to nobody, he just walks up behind you,” said a building maintenance worker, who declined to give his name. “Walks up and down, smoking. He doesn’t talk much.”

The crime left neighbors heartsick.

“All the sudden, I heard a boom,” recalled a woman named Tzipporah, and whose backyard abuts the courtyard.

“I didn’t know what was happening,” she said. “And then this morning there were [police] everywhere,” she said.

“I didn’t connect the memory until now. It’s terrifying.”

“It’s a four-year-old kid,” said first floor neighbor Mario Martino, who’s lived in the building for 36 years.

“You think, what was going through his head when he was getting thrown off that roof?”

Additional reporting by Khrystina Narizhnaya, Sydney Denmark and Laura Italiano