A 23-year-old man with a history of paranoia and aggressive tendencies was charged Thursday with fatally stabbing a female runner in Logan Circle in what authorities said was a random attack.

The suspect, Anthony Marquell Crawford, was arrested in a park he frequented a mile north of where the stabbing occurred. Court records show the suspect has a history of mental illness and has used synthetic drugs that can cause delusions and deranged behavior.

He was charged with first-degree murder in the killing of Wendy Martinez, 35, the chief of staff for a start-up Internet tech company, who was attacked shortly before 8 p.m. while running near her apartment.

Police described a brutal attack at P and 11th streets NW for which there is no explanation. Police said the petite marathon runner was stabbed six times in the head and neck, and once in the back. The attacker ran, police said, discarding a bloody knife and a distinctive mustard-colored shirt as Martinez stumbled into a Chinese carryout and bystanders tried in vain to save her life.

The stabbing in the gentrifying neighborhood of expensive rowhouses and upscale restaurants has unnerved residents in an area that experiences little violent crime. The randomness of the attack has added to the fear, which Mayor Muriel E. Bowser (D) acknowledged Thursday when she said it was “certainly damaging to all our senses of safety.”

On Thursday evening, more than 200 people gathered for a vigil in Martinez’s memory near the site where she was slain, remembering her as caring and upbeat. They struggled to comprehend the death of a woman who was recently engaged to be married and was thriving in her job.

Wendy Martinez’s mother, Cora Martinez, said she forgives her daughter’s assailant — who she believes was manipulated by an evil force.

“My heart has been broken into 1,000 pieces, but I forgive that man,” she said.

Earlier, a D.C. Superior Court judge ordered Crawford detained until a hearing Oct. 11. There was heavy security, with U.S. marshals posted around the courtroom.

Assistant U.S. Attorney Katie Earnest repeatedly called the killing “vicious” and said the attack was recorded on security video.

“This was a horrible, random killing, a horrible and terrifying manner to die,” Earnest said.

Crawford at one point began to speak, asking: “Aw, man. Can I say something?” — as his attorney, Eugene Ohm with the D.C. Public Defender Service, whispered in his ear to remain quiet.

Ohm said there was no evidence linking his client to the killing and disputed witness accounts. He called Crawford’s arrest “a rush to judgment by police.” The defendant’s family sat in the courtroom but declined to comment.

Authorities said Crawford tested positive for cocaine at the time of his arrest.

Although authorities said Crawford has no recent arrests related to violence, court records obtained by The Washington Post show that in 2012 he was charged as a juvenile with felony assault. The then-16-year-old was found guilty of simple assault and ordered to remain under juvenile supervision until he turned 21.

He was freed at one point, but in 2015, when he was 20, court records show he disappeared from a group home for a month.

About that time he was taken to the United Medical Center for a psychiatric evaluation. Court documents show a doctor noted that Crawford was addicted to drugs and exhibited “seriously self-destructive behavior creating an imminent danger.” District officials tried to have Crawford involuntarily committed for a year, writing that he was “likely to injure self or others.”

In November 2015, Crawford told hospital staff, “I’m God, sometimes I feel depressed,” according to a court document quoting a psychiatrist. The doctor said Crawford had used synthetic hallucinogens, had refused to take medication and was “quick to become paranoid that others are after him or trying to trick him. He also quickly becomes agitated and aggressive.

But a month later, in December 2015, the D.C. Department of Behavioral Health, through an attorney with the Office of the Attorney General, dismissed the petition to hold Crawford. The government offered no explanation in court documents, and officials at both agencies declined to comment, citing privacy laws surrounding juveniles and health issues.

D.C. Police Chief Peter Newsham said there was no indication that Martinez had a confrontation with Crawford. A witness described crossing a street “to try and avoid” Crawford moments before the attack.

Afterward, several people gave police detailed descriptions of the attacker and a police officer recognized Crawford as a suspect in a theft case, court papers say. Others told police that Crawford frequented a park on Girard Street.

Newsham said investigators are beginning to dive into Crawford’s background, which includes a charge of theft under $100 in July in Prince George’s County. The chief told reporters that authorities “will look very carefully at the suspect’s past to see if there is something to lead to this kind of incident that we could have potentially taken care of.”

Martinez, who was born in Nicaragua and raised in Florida, graduated from Georgetown University with a master’s in Latin American studies in 2012. On Thursday, Sen. Marco Rubio ­(R-Fla.) tweeted about Martinez, a graduate of the Congressional Hispanic Leadership Institute.

“The death of Wendy Martinez is so senseless, tragic & heartbreaking,” Rubio wrote in the tweet. “Now the life & career ahead of her was cut short. Can’t even begin to imagine the pain those who loved her are going through.”

At the candlelight vigil at Logan Circle, friends and family took turns recounting the numerous ways in which Martinez had positively impacted their lives

Her fiance, Daniel Hincapie, and brother, Juan Carlos Martinez, implored those in attendance not to let Martinez’s killing change their perception of Washington, a city Wendy loved living in.

“This type of incident shouldn’t prevent us from being who we are as a city, as runners — as people,” Hincapie said.

An earlier version of this article mistakenly said the United Medical Center has been closed.

Mike DeBonis contributed to this report.