The errand that nearly cost Ralph Yarl his life was of the sort that falls to older brothers everywhere.

Ralph, a Black 16-year-old in Kansas City, Mo., had been sent to pick up his younger twin brothers at a friend’s house on Thursday evening, his family said. But he mixed up the address, finding himself in front of a house on Northeast 115 Street, instead of Northeast 115th Terrace.

The white man who answered the door there shot him in the head and again in the arm after he fell, according to prosecutors. Somehow, Ralph made his way, bleeding, to another nearby house. There, he was told to lie on the ground while someone called for help, his family said.

The homeowner who shot him, Andrew D. Lester, 84, was taken into custody by the police for 24 hours, then released without charges on Friday. Over the weekend, anger began to spread in the community. Protesters marched on Mr. Lester’s home on Sunday, while the Kansas City police chief, Stacey Graves, acknowledged the public frustration at a news conference. The teenager was released from the hospital on Sunday evening, his father said.

As pressure mounted on Monday afternoon, the Police Department said in a statement that it had submitted the case file to the Clay County prosecuting attorney’s office. The prosecutor, Zachary Thompson, publicly identified Mr. Lester a few hours later and announced that he had been charged, saying what many already believed: “There was a racial component to the case.”

Mr. Thompson said Mr. Lester had been charged with assault in the first degree, a class-A felony, and could face life in prison if convicted. He also was charged with armed criminal action, which carries a maximum penalty of 15 years in prison, Mr. Thompson said.

It was not clear if the teenager had knocked on Mr. Lester’s door or if he rang the doorbell, but he did not “cross the threshold” into the man’s home, Mr. Thompson said. The shots from a .32-caliber handgun were fired through a glass door, the prosecutor said, adding that there was no indication that “any words were exchanged.”

“We understand how frustrating this has been, but I can assure you that the criminal justice system is working, and will continue to work,” Mr. Thompson said.

Mr. Lester was not in custody when the charges were announced. Mr. Thompson said at the news conference that a warrant had been issued for his arrest, and that his bail had been set at $200,000.

“I don’t have any information regarding his specific whereabouts,” he added, “but it’s my understanding law enforcement is aware of the situation and taking all appropriate action.”

The teenager’s father, Paul Yarl, said in a phone interview on Monday evening that his son underwent surgery over the weekend to remove the bullets. He was able to walk out of the hospital on Sunday evening and was expected to make a full recovery, his father said. The first bullet hit his son’s forehead on the side of his face, close to the hairline, he said, and the second hit his right arm.

Mr. Yarl said that he was relieved when the charges were finally announced.

He said that he was confused that Mr. Lester had been “allowed to go home and sleep” but that his main concern was for other Black children. “He could have repeated it with the next kid that looked like Ralph,” he said.

Mr. Yarl said he learned that his son had been shot in a call from the boy’s mother on Friday morning and drove from his home in Indianapolis to Kansas City, where he visited his son and also joined the protest over the weekend.

“I’m still shocked. He’s a good kid,” he said, describing his son as an athlete who loves music and video games, and who excels in school. The parents, who are Liberian immigrants, have been divorced since 2017.

Mayor Quinton Lucas of Kansas City said in an interview on Monday before the charges were announced that he was “heartbroken and angry about the situation that we find ourselves in.”

“You’ve heard about driving while Black,” said Mr. Lucas, who is Black. “You’ve heard about all the other issues that Black people confront in life. Can you not knock on the door while Black? It’s almost like you can’t exist.”

Later on Monday, Mr. Lucas said on Twitter that the charges against Mr. Lester were a “first step towards justice for Ralph Yarl.” He also said that he had spoken with Ralph’s mother and had “shared with her my personal commitment to ensuring we find justice for her son, her family, and all hurting now in our City.”

The White House said on Monday night that President Biden had spoken by phone to Ralph and that he had “shared his hope for a swift recovery.”

Before the charges were announced, most of the details about the shooting had come from family members and their lawyers, Ben Crump and S. Lee Merritt, as The Kansas City Star and other local media outlets covered the growing controversy over the release of Mr. Lester, who had not yet been publicly identified.

“There can be no excuse for the release of this armed and dangerous suspect after admitting to shooting an unarmed, nonthreatening and defenseless teenager that rang his doorbell,” Mr. Crump and Mr. Merritt wrote in a joint statement on Sunday.

Mr. Crump linked to a fund-raising page started by Ralph’s aunt, Faith Spoonmore, who wrote that her nephew, a high school junior, did not have his phone with him when he went to get his brothers.

“He mistakenly went to the wrong house, one block away from the house where his siblings were,” she wrote. She said that her nephew pulled into the driveway and rang the doorbell and that the man who came to the door shot Ralph in the head.

“My nephew fell to the ground, and the man shot him again,” Ms. Spoonmore wrote. “Ralph was then able to get up and run to the neighbor’s house, looking for help. Unfortunately, he had to run to three different homes before someone finally agreed to help him after he was told to lie on the ground with his hands up.”

Chief Graves said on Sunday that the police were called to the scene around 10 p.m. During the news conference, an investigator declined to say whether it was the homeowner who had called 911.

The gunman was released after being held for the maximum 24-hour period allowed without charges under state law in a felony investigation, the chief said at the news conference.

Chief Graves said that the teenager was expected to give a formal statement to investigators when his injuries allow. She also said that there was a “potential” self-defense or “stand your ground” element that investigators were examining.

But the following day, Mayor Lucas said that Missouri’s Stand Your Ground law, which was adopted in 2016, should not apply in this case.

“If Stand Your Ground really lets somebody just shoot somebody that rings a doorbell,” he said, “that put the life of every postal worker, every campaigner, every Amazon delivery person at risk in this country.”

William Lamb contributed reporting and Sheelagh McNeill contributed research.