It was just before 8:30 a.m. Monday, the police said, when a man approached a construction worker on West 19th Street in Manhattan and, without warning, stabbed him in the gut and ran off. The victim was soon declared dead.

A violent spree was just starting, the police said.

By 11 a.m., the assailant had fatally stabbed a man who was fishing by the side of the East River, and had attacked a 36-year-old woman near the United Nations. She was pronounced dead several hours later, the police said.

The rampage ended when a cabdriver who had seen the third stabbing followed the attacker from the crime scene and then alerted a police officer, who took the man into custody. The man’s clothes were spattered with blood, and he had two bloody knives, the police said.

Late Monday, the police said the man, Ramon Rivera, was being charged with three counts of first-degree murder. Mr. Rivera, 51, appeared to be homeless, the police said. He was released from the Department of Correction’s custody last month after being jailed on burglary and assault charges, a spokeswoman for the agency said.

Although major crime overall is down slightly in New York City so far this year compared with last year and the year before, the random, deadly attacks in broad daylight were likely to have an unsettling effect on the public’s perception of how safe the city is.

Mayor Eric Adams, speaking with police leaders at a news conference before Mr. Rivera was charged, said that officials were still reviewing the attacker’s criminal record, but that there were “serious questions on why he was on the street.” The mayor also said the attacker had “serious mental health issues.”

“Today, we have three innocent New Yorkers who were victims of a terrible, terrible assault,” Mr. Adams said. The stabbings, he added, were “a clear example of a criminal justice system and a mental health system that continues to fail New Yorkers.”

The police identified the construction worker who was killed as Angel Lata Landi, 36, of Peekskill, N.Y. The other victims had not been identified as of late Monday pending notification of their families.

Mr. Rivera had been arrested at least eight times in the city, most recently on a larceny charge in Manhattan in October, according to officials. That case remained active as of Monday, and the Legal Aid Society lawyer representing Mr. Rivera in the case declined to comment.

The crimes Mr. Rivera was accused of in New York before this year typically involved shoplifting, according to a senior law enforcement official who spoke on the condition of anonymity to discuss a continuing investigation. He did not appear to have been charged with weapons-related crimes, the official said.

At one point, the official said, Mr. Rivera appears to have stayed at the main men’s intake shelter near Bellevue Hospital, but he usually gave the police one of two addresses: one on University Avenue in the Bronx, the other in Kissimmee, Fla.

Police officers in New York City first encountered Mr. Rivera last year, according to an internal police document that details his criminal and mental health history.

In the first interaction, on Nov. 19, 2023, officers found Mr. Rivera on a Flushing, Queens, curb. He was acting erratically and complaining of pain in his left arm, the document says.

About three weeks later in Brooklyn, the document says, Mr. Rivera called the police to say he was feeling suicidal and homicidal. Emergency service workers treated him, and the police took him to Woodhull Hospital.

Mr. Rivera has been arrested several times since. The first came last year on Dec. 13 when he was charged with stealing several steaks from a Bronx supermarket, according to a spokeswoman for the Bronx district attorney, Darcel D. Clark.

On Christmas Eve, he was charged in Manhattan with two counts of burglary for entering a building with criminal intent, according to the internal document.

On Feb. 19 of this year, he was again charged with illegally entering a building with criminal intent on three separate occasions in Manhattan, the document says.

Mr. Rivera was held in several city jails from Feb. 19 to Oct. 17, according to a Department of Correction spokeswoman. On May 7, while in custody, he was charged with assaulting a police officer and an emergency medical worker at a psychiatric prison ward at Bellevue Hospital, the police document says.

His most recent arrest was the day he was released, when he was charged with larceny for stealing a bowl, the police document says.

Mr. Rivera’s criminal record outside New York dates back to a battery charge in Polk County, Fla., in May 2003, the document says. He was arrested four more times in Florida on various charges from 2006 to 2010. In 2017 and 2018, he was charged with assault in two Ohio cases.

It was not immediately clear how many of his arrests resulted in convictions.

The first of the attacks on Monday occurred on West 19th Street near 10th Avenue in Chelsea, when a knife-wielding assailant stabbed Mr. Lato Landi in the abdomen outside the job site where he was employed, Joseph Kenny, the Police Department’s chief of detectives, said at the news conference. Mr. Lato Landi was pronounced dead at Bellevue Hospital, Chief Kenny said.

A snippet of security footage captured by a camera on a nearby building shows the assailant before the attack, standing near a car as he pulls on a gray hooded sweatshirt, a hat and gloves, reaches into a bag and pulls out a knife.

Other footage, taken from a co-op building directly across the street from where the stabbing happened, shows the man in the sweatshirt walking down a mostly empty block and holding the bag. After a short distance, he disappears behind a tree in the foreground of the frame.

Seconds later, Mr. Lato Landi, wearing a hard hat and bright-colored safety vest, comes running into the frame. He clutches his stomach and stands on the sidewalk as a woman with a stroller hurries into the building behind the man just before he topples to the ground.

Elton Wells, the co-op’s board president, said many of the building’s residents had been calling him since the morning in a panic.

“People were pretty stunned by the whole thing,” Mr. Wells, 52, said. “My phone’s been going off the hook all morning.”

About two hours later, the attacker struck again, this time on East 30th Street near Franklin D. Roosevelt Drive, where he stabbed the fisherman repeatedly, Chief Kenny said. That victim, 67, was also pronounced dead at Bellevue Hospital. (The police originally said he was 68.)

Late Monday afternoon, a white sheet covered a bloodstained section of sidewalk near where the killing occurred. Latex gloves littered the idyllic stretch, which connects the United Nations and a commuter ferry terminal. Commuters and joggers sidestepped the crime scene until firefighters used their hoses to wash off the blood stains around 5 p.m.

Kevin O’Keefe, a father of three teenagers and a member of the local community board, said the attack was unnerving, especially since the area is often filled with children going to and from five nearby schools in the morning.

“This is a community, this is not the big fearful city,” Mr. O’Keefe said. “And that’s why I feel like incidents like this pierce the heart of the city.”

The third attack occurred about a half-hour later, when the 36-year-old woman was stabbed several times at 42nd Street and First Avenue, Chief Kenny said. She was taken to NewYork Presbyterian-Weill Cornell Medical Center in critical condition and pronounced dead Monday night.

As horrific as the crimes were, there was potential for even greater carnage. The police said they believed the attacker had traveled by foot, roaming three miles across Manhattan for two and a half hours armed with two knives and a murderous impulse to use them.

Reporting was contributed by Andy Newman, Connor Michael Greene and Wesley Parnell. Kirsten Noyes contributed research.