The decadeslong hunt for a masked gunman who was dubbed the Golden State Killer while he terrorized California during the 1970s and 80s is now over, police declared Wednesday.

Joseph James DeAngelo, a 72-year-old former police officer, was arrested overnight at his suburban Sacramento home and was being held without bail at the Sacramento County jail, officials said.

DeAngelo was taken into custody on a warrant out of Ventura County, California, for two murder charges, but police believe that he killed a dozen people, committed 45 rapes and burglarized 120 homes during a 12- year reign of terror.

"We all knew as part of this team that we were looking for a needle in a haystack, but we also all knew that the needle was there," Sacramento County District Attorney Anne Marie Schubert said at a news conference with Sheriff Scott Jones and other law enforcement officials. "We found the needle in the haystack and it was here in Sacramento."

Jones said they used "discarded DNA" to confirm that DeAngelo was their man and arrested him at his modest home in Citrus Heights. He did not explain what they meant by "discarded DNA" but said DeAngelo had been under surveillance for six days and that they caught him by surprise when they moved in to arrest him.

"This was a true convergence of emerging technology and dogged determination by detectives," Jones said. "In this case justice was delayed. It wasn't swift but it will be sure."

DeAngelo was charged with two counts of murder in the March 1980 killings of Lyman and Charlene Smith. The charges include special circumstances of multiple murders, murder during the commission of a rape, and murder during the commission of a burglary.

But few details were released about the suspect, a Navy vet who was an officer in the police departments of two small California cities, Exeter and Auburn, during the 1970s.

DeAngelo was fired from the Auburn job in August 1979 for shoplifting a hammer and dog repellent from a store, but Jones said investigators are still not sure whether he raped or killed anybody while on duty.

"We are trying to fill a lot of gaps in his life," the sheriff said. "We don't have a full picture yet."

DeAngelo has grown children who are cooperating with investigators, he added.

"We have interviewed some family members," Jones said. "This was certainly a shock to them."

Also at the news conference was Bruce Harrington, whose brother Keith Harrington and sister-in-law Patrice Harrington were beaten to death in August 1980 at their Dana Point home. They were newlyweds.

Joseph James DeAngelo Sacramento County Sheriff's Department

After the couple were killed, Harrington bankrolled an initiative passed by California voters in 2004 that mandates collection of DNA samples from people arrested in felony cases.

"Bravo, bravo," he said, applauding the detectives who arrested DeAngelo. And to the surviving loved ones of the victims, he added this:

"Sleep better tonight, he isn't coming through the window. He's in jail, and he's history."

DeAngelo, who was also dubbed the East Area Rapist and the Original Night Stalker, was blamed for a raft of crimes up and down California starting in 1974 and ending — for reasons still unexplained — in 1986. His victims ranged in age from 13 to 41.

From Sacramento south to the Los Angeles suburbs, the masked gunman raped women who were home alone and women who were with their children, and killed women and men together, police said.

When the killer went underground, police kept looking, and in 2016 the FBI offered a $50,000 reward for information leading to his arrest.

The search took on a renewed urgency earlier this year after a book about the case written by Michelle McNamara called "I'll Be Gone in the Dark" was published in February with the help of her husband, comedian and actor Patton Oswalt. McNamara, 46, died in 2016, leaving the book unfinished.

Contra Costa County cold-case investigator Paul Holes, who had worked on this case for decades, told NBC's Megyn Kelly last month that the serial killer would follow the news accounts of his crimes and kept a step ahead of the police by changing the way he targeted his victims.

“He covered his trail very well,” Holes said. “What he didn’t account for was DNA technology.”

He left behind plenty of DNA that police might be able to use to identify him, Holes said.

Jane Carson-Sandler, who said she was raped by the killer in 1976, told Kelly that she "used to want to punch him in the face."

"It took me a long time to be able to forgive him," she said. "He’s a very sick man and I was the one carrying all these feelings around. Once I was able to forgive him, I felt a tremendous freedom. I want to look him in the eye."