ALFRED — A 76-year-old Biddeford man charged with killing two teenagers in an apartment in his home suffered a “mini-stroke” that changed his behavior just months before the December 2012 shootings, a psychologist testified in court Thursday.

James Pak, who has pleaded not guilty by reason of insanity to two counts of murder and other charges, became increasingly concerned about his failing memory after his July 2012 stroke, and his wife, Armit Pak, noticed that he lost his temper more often, according to psychologist Kerry Drach.

Drach testified in York County Superior Court in Alfred as the first witness in a hearing to determine whether Pak is competent to stand trial in the deaths of Derrick Thompson, 19, and Alivia Welch, 18.

Authorities say Pak fatally shot Thompson and Welch on Dec. 29, 2012, in the apartment that he rented to Thompson and his mother, Susan Johnson, 46, after a dispute over parking. Johnson was also shot but survived and called 911. Police had been called to the home earlier, but left minutes before the shootings, deeming the landlord-tenant dispute was under control.

Drach, who does court-ordered work for the State Forensic Service, said he interviewed Pak twice in 2013, once at Riverview Psychiatric Center in Augusta and later at the York County Jail in Alfred. He also interviewed Armit Pak by phone before writing his report.

“(Armit Pak) noticed changes in his behavior since the stroke,” Drach testified. “She also said that, emotionally, that he had a history of having a temper, and since the stroke he had been having more temper issues.”

Drach testified that he found Pak showed possible signs of dementia, did not seem to understand the gravity of the charges against him and had limited ability to grasp complex court proceedings.

“He tended to perseverate (talk on and on) on speaking negatively about the victims of his alleged crimes, about how it was all their fault,” Drach said. “He would get all tangled up in that, and I would have to redirect him to the question.”

Drach said he asked that Pak undergo further testing regarding his competency to stand trial and whether he suffered from dementia.

But a second psychologist, Robert Riley, testified that he examined Pak twice in 2014 and found him competent to stand trial and showing no signs of dementia.

The judge made no immediate ruling about Pak’s mental state and whether the case against him can proceed to trial. Riley was unable to conclude his testimony before court adjourned for the day, and the hearing will resume at an unscheduled date this spring.

Drach and Riley were both called to testify by a prosecutor, Assistant Attorney General Deborah Cashman. Pak’s attorneys, Joel Vincent and Lawrence Goodglass, are expected to call their own expert witness to testify when the hearing resumes.

Pak is accused of shooting Thompson, Welch and Johnson just minutes after Biddeford police had left the tenants’ apartment.

Court documents say Pak waited for police to leave, got a gun, opened the door to the apartment and said: “I am going to shoot you. I am going to shoot you all.”

He shot Johnson first, then Thompson, then Welch, court documents say.

Johnson suffered gunshot wounds to the back and arm but survived. The two teenagers were dead by the time emergency responders arrived.

In addition to the two counts of murder, Pak is charged with attempted murder, one count of elevated aggravated assault and burglary. He has remained in custody since being arrested the day of the shooting.