WASHINGTON — When police confronted Tamerlan Tsarnaev four nights after the Boston Marathon bombing last year, he leaped from his car with a 9-mm. semiautomatic pistol and opened fire.

He critically wounded one officer and, despite being shot himself, kept firing until the gun emptied or jammed. In a final act of defiance, he threw the pistol at police before he was killed.

The tale of that handgun, a black Ruger P95, Serial Number 317-87693, offers new insights into the Boston tragedy and holds warnings of other potential dangers.

Its journey from a street gang that peddled crack cocaine in Portland, Maine, to the grisly shootout in a Boston suburb tells much about illicit drug and gun trafficking in New England, and perhaps more about Tsarnaev.

Authorities believe Tsarnaev’s ties to the illicit drug trade in Maine helped finance his six-month trip to the southern Russian republics of Chechnya and Dagestan in early 2012, where he became radicalized. Drug money, they say, also may have helped him buy components of the bomb that killed three people and injured more than 260 on April 15, 2013.

Portland is home to a trio of violent gangs called the True Somali Bloods, the Little Rascals Gang and a newly formed faction of the Crips Nation, according to the FBI.

Federal and state law enforcement authorities had investigated the rival gangs for years with an operation officially called “Run This Town.”

A Los Angeles native first legally purchased the Ruger. He told police he passed it to one of the Portland gang leaders, a man known as Icy. But there the trail goes cold.

Precisely how Tsarnaev got the gun is still unclear. But police say he used it to wound Richard Donohue, a Massachusetts Bay Transportation Authority officer, during the shootout. The weapon also was used to kill Sean Collier, a 27-year-old MIT security officer, in his patrol car earlier that night.

No one has been charged in those shootings. Tsarnaev’s younger brother, Dzhokhar, faces 30 federal charges, including using a weapon of mass destruction, for his alleged role in the bombing. Prosecutors have said they will seek the death penalty if he is convicted. His trial is scheduled to begin this fall in Boston.

After the bombing, police found evidence that they said linked Tamerlan Tsarnaev to several brutal drug-related killings. During the night of Sept. 11, 2011, three men had their throats slit in an apartment in Waltham, in Boston’s western suburbs.

Police said thousands of dollars’ worth of marijuana and cash were sprinkled over the mutilated bodies, suggesting robbery was not the motive. The slayings remain unsolved.

The gun trail began when Massachusetts State Police took custody of the 38-ounce Ruger found at Dexter Avenue and Laurel Street in Watertown, another Boston suburb, moments after the shootout.

They immediately noticed that the eight-digit serial number had been filed down and was all but obliterated, a ploy criminals use to hide a gun’s origin.

But after a week of forensic work and lab tests, police technicians managed to “raise” seven of the numbers. They ultimately found and matched the missing digit, which was the 8.

Justice Department records obtained by the Tribune Washington Bureau show that an agent for the federal Bureau of Alcohol, Tobacco, Firearms and Explosives in Boston formally requested a trace of the Ruger on April 26, 2013.

He marked the file “URGENT-HIGH PROFILE HOMICIDE.”

The trace led to a Cabela’s, a popular hunting and fishing outfitter with stores across the country, in Scarborough, Maine, just south of Portland. Records showed the gun was purchased Nov. 27, 2011, as part of a “multiple handgun sale.”

The buyer was identified as Danny Sun Jr., a Los Angeles native living in South Portland, a Portland suburb.

Five months earlier, on June 23, 2011, law enforcement authorities had set up a joint Organized Crime Drug Enforcement Task Force to investigate the three Portland drug gangs.

In all, some 30 people were identified as potential suspects. Four days after it was launched, a judge granted the task force authority to tap telephones, cellphones and other mobile communication devices.

No evidence indicates that Tsarnaev’s name or communications came up during the investigation.

But two weeks after the bombing, on May 1, 2013, Sun was arrested on a warrant in Westbrook, Maine, for failing to appear on an outstanding traffic case.

According to government sources, Sun, 26, was asked about the Ruger. After spending 50 hours in the Cumberland County Jail, he told police he had passed his gun to Biniam Tsegai.

Tsegai, 27, was well known to local police. An immigrant from Eritrea, he goes by the moniker Icy.

Tsegai was picked up three weeks later, on May 23, 2013, on Free Street in Portland on a fugitive warrant from a 2009 robbery case. He was taken to the Cumberland County Jail.

A federal grand jury in Portland charged Tsegai with conspiracy to distribute and possession with intent to distribute crack cocaine.

Michael J. Conley, an assistant U.S. attorney in Portland, noted in papers filed in federal court in January that the cocaine “had been brought to Maine from Boston.”

Tsegai’s rap sheet shows “almost five pages of police involvement,” Conley said. Charges include disorderly conduct, criminal trespass, reckless driving, robbery and refusing to submit to arrest.

Conley said in a detention hearing in June that Tsegai always seemed to be “around” when police were called to a stabbing, a shooting or other crime scene. He often carried $800 or $1,200 in cash, Conley said, although he only worked at a Wendy’s or a convenience store.

Tsegai refused to talk to police about the Ruger or anything else after his arrest. He remains in jail awaiting trial, facing a maximum sentence of 40 years if convicted of the drug charges.

According to court records, federal wiretaps of his jailhouse phone calls show he has warned others not to talk.

“Stay off the phone,” he admonished. “Change your phones, everything.” He boasted: “I told the police to get … out of here.”

Defense attorney Peter J. Cyr told the court that Tsegai “has no obligation whatsoever to speak to the government or any of the government’s agents.”