The nanny on trial for the murder of two children in her charge told a doctor she was being courted by Satan in the month ­before the slayings, jurors heard Tuesday.

“I felt like the devil was possessing me, wanting me to be his,” Yoselyn Ortega proclaimed as she lay shackled to a hospital bed after killing Lucia Krim, 6, and her brother Leo, 2, forensic psychiatrist Karen Rosenbaum testified. “That the devil wanted me for himself.

“She said there was a black shadow that was following her,” Rosenbaum said she was told in December 2012. “[Ortega] said she was hearing voices to kill herself and others.”

“[Ortega] finally told me, several interviews in, that the voices told her to kill people, that they told her to kill herself, and eventually that they told her to kill the children,” the psychiatrist told the court.