DOYLESTOWN, Pa. — A week after four young men disappeared in the suburbs of Philadelphia, and one day after investigators found human remains buried on a nearby farm, the son of the farm’s owners confessed to killing all four, his lawyer said on Thursday.

Cosmo DiNardo, 20, who knew the victims, had been described by the authorities as a “person of interest” in the disappearances, and prosecutors had filed lesser charges against him this week to put him in jail while they investigated the disappearances. Officials gave no indication of a motive for the killings, but Mr. DiNardo suffered from mental illness, he had multiple run-ins with the local police, and an acquaintance said he had talked about killing people.

“Mr. DiNardo this evening confessed to the district attorney to his participation or commission in the murders of the four young men,” one of his lawyers, Paul Lang, told reporters late Thursday outside the Bucks County Court of Common Pleas. “In exchange for that confession, Mr. DiNardo was promised by the district attorney that he will spare his life by not invoking the death penalty.”

Asked whether Mr. DiNardo, who lives with his parents in Bensalem, Pa., acted alone, Mr. Lang said, “I can’t answer that.”

Matthew D. Weintraub, the Bucks County district attorney, had no immediate comment, but scheduled a news conference for later in the evening.

As Mr. DiNardo was being led by the authorities into a police van on Thursday evening, reporters asked him whether he had any sympathy for the victims’ families. “I’m sorry,” he said.

On Wednesday, Mr. Weintraub said the remains of one of the missing men, Dean Finocchiaro, 19, had been found in a 12.5-foot-deep “common grave” on the sprawling farm in Solebury, Pa., owned by Mr. DiNardo’s parents. Officials have not said whether they have identified — there, or elsewhere — the remains of the other men, Mark Sturgis, 22; Thomas Meo, 21; and Jimi Taro Patrick, 19.

Mr. DiNardo has had 30 “contacts” with the Bensalem Police Department over the last six years, the department’s director, Frederick Harran, said in a telephone interview. He declined to elaborate on what they involved, but said the suspect was well known to the police.

Mr. Harran said Mr. DiNardo had been sent involuntarily to a mental hospital last summer, at the request of a family member, but said he did not know the specific complaint, or how long he was held there. This week, a prosecutor and one of Mr. DiNardo’s lawyers described him as mentally ill.

On Feb. 9, police responded to a report of gunfire in Mr. DiNardo’s neighborhood and found him in his car with a shotgun, and he told the officers that he had been involuntarily committed, Mr. Harran said. He was arrested on a gun charge, which was later dropped. He was legally prohibited from owning a firearm because he had been involuntarily committed.

Another Bensalem man, Eric Beitz, who was friends with Mr. Meo and Mr. Sturgis, told The Philadelphia Inquirer that Mr. DiNardo had spent considerable time with them recently, and spoke of “weird things like killing people and having people killed.” He also said Mr. DiNardo sold guns.

On Thursday, Mr. Beitz, 20, confirmed to The Times that what the Inquirer had reported was correct, but said he would not say more, at the request of the police and the victims’ families.

Mr. Finocchiaro, who graduated from Neshaminy High School, just outside Bensalem, and Mr. DiNardo were both members of a Facebook group for people in eastern Pennsylvania who are interested in buying and selling all-terrain vehicles and dirt bikes. The Inquirer reported that text messages shared among a group of young men showed that they knew each other.

Mr. Patrick and Mr. DiNardo went to the same small, private high school, Holy Ghost Preparatory in Bensalem, graduating one year apart.

Mr. Meo and Mr. Sturgis were best friends who both graduated from Bensalem High School, and Mr. Sturgis’s father said he had heard the young men mention Mr. Finocchiaro.

Map | Site of Exhumation

The four missing men were last seen from Wednesday to Friday of last week, and the search for them has been one of the biggest law enforcement operations ever mounted in Bucks County, a fast-growing region of suburban subdivisions, farms and country estates north of Philadelphia.

A clue that emerged on Saturday afternoon focused the hunt on the DiNardo farm nearly 20 miles north of Bensalem: Mr. Finocchiaro’s cellphone was traced to that location.

Investigators searching another property nearby, also owned by the DiNardos, found Mr. Meo’s car in the garage, and Mr. Sturgis’s car was found in a parking lot a few miles away. Mr. Weintraub has said that Mr. DiNardo tried to sell Mr. Meo’s car for $500 to another person, who called police.

Local authorities and a team from the Philadelphia office of the F.B.I., along with cadaver dogs, combed through the farm, sifting the soil between rows of corn, digging up concrete with a backhoe, and surveying the land on all-terrain vehicles.

The dogs led detectives to the grave, Mr. Weintraub said. The body of Mr. Finocchiaro, who vanished around 6:30 p.m. on Friday in Middletown Township, was identified on Wednesday.

Interactive Feature | Breaking News Emails Sign up to receive an email from The New York Times as soon as important news breaks around the world.

On Monday, Mr. DiNardo was rearrested on the gun charge from earlier this year. Prosecutors had asked the police in June to rearrest him.

Mr. DiNardo’s father posted bail on Tuesday night, but prosecutors charged him the following day with stealing Mr. Meo’s car, and had him arrested again. The second time, a judge set bail at $5 million, and he stayed in jail.

The first of the victims to disappear, Mr. Patrick, was last seen around 6 p.m. on July 5 in Newtown Township, Pa., and did not show up for work the next day, the authorities said. According to a statement released by his family, he lived with his grandparents in Newtown, Pa., had just finished his first year at Loyola University in Baltimore, and worked at a restaurant in Buckingham, Pa.

Last Friday around 6 p.m., Mr. Sturgis told his father, Mark Potash, that he was going to meet Mr. Meo. Both young men worked for Mr. Potash’s construction business, but on Saturday morning, they did not report for work.

Growing more concerned, Mr. Potash dialed his son’s cellphone, but it went straight to his voice mail. He dialed it again and again, but it never rang.

Even then, Mr. Potash said, he figured their cellphone batteries had died. Later on Saturday, Mr. Potash said, he called Mr. Meo’s parents, leading to a chain of calls among friends and family members. The two young men were inseparable, and no one had heard from either of them.

“I was hopeful that they just had a wild night,” Mr. Potash said. “My whole way to work, I thought these guys will be at work and will explain themselves.”