YORK, Maine — A man suspected of robbing 14 banks in Massachusetts and Maine, including the local Bangor Savings branch, was arrested Tuesday night in Salem, N.H., by a federal task force created to hunt him, York police Capt. Kevin LeConte said Wednesday.

York detectives got a good picture from bank surveillance cameras of the man believed to be the “Merrimack Valley Bandit” and sent it to other partnering law enforcement agencies in the region, LeConte said. A member of the federal Drug Enforcement Agency in Massachusetts recognized the suspect, the police captain said.

“He said, ‘That looks like one of the guys I used to deal with,’” LeConte said. “We tracked him down and now he’s being charged with our bank robbery.”

Rafael Beamud Jr., 32, of both Lowell, Mass., and Salem, N.H., was captured in Salem during a traffic stop, Capt. Chris McCarthy of the Methuen (Mass.) Police Department said late Tuesday night.

“Some evidence that developed earlier today led to his arrest,” the police captain said by phone with obvious excitement in his voice. “He did 14 robberies and took approximately $40,000-$50,000.”

Methuen police Chief Joseph Solomon issued a tweet about the arrest at 4:42 p.m. Tuesday.

Beamud, who was charged with armed bank robbery, is in federal custody and made his initial appearance in U.S. District Court in Boston Wednesday afternoon, Christina DiIorio-Sterling, a U.S. Department of Justice public information officer in Boston, said in an email.

“This investigation encompasses an approximate two-month period, beginning in February of 2013, during which there were 14 bank robberies throughout the Merrimack Valley area of Massachusetts and York County, Maine,” FBI special agent Laurence Travaglia states in the criminal complaint that was filed Wednesday in court. “There were physical similarities and methods of operation including the use of a partial mask and a small-framed semi-automatic handgun.”

The bandit’s first of 13 bank robberies in Massachusetts occurred on Feb. 21 at TD Bank in Methuen. Beamud told the FBI agent that he brought a small, black .380-caliber semi-automatic handgun with a clip into the bank and demanded money.

“Beamud stated that he pulled the ‘slide’ on the gun to intimidate the bank employees,” the criminal complaint states.

When he chambered the round it caused a bullet to eject from the gun, the FBI agent said.

“Beamud stated he did not know that a round was in the chamber and its ejection surprised him,” Travaglia states. “Beamud stated he picked up the round.”

Beamud also threw several plastic bags at the teller when he demanded the money and was “apparently unaware that he had left a bag behind,” the FBI agent said.

The Massachusetts State Police crime scene services unit collected the bags and the Bay State’s crime lab found three of his fingerprints on the forgotten bag, the criminal complaint states. The crime lab ran the fingerprints through their computer system and on Tuesday identified Beamud as the suspect.

The maroon Kia SUV he was driving on Tuesday night when stopped in Salem “contained the .380 gun used during the robberies; bullets; a mask; and other articles of clothing that he used during the robberies,” Travaglia said. “He also stated that the car contained oxycodone pills which he obtained during a pharmacy robbery in New Hampshire.”

A $10,000 reward was offered by the FBI “for information leading directly to the arrest of the robber,” but FBI spokeswoman Katherine Gulotta, who works out of the Boston office, could not say whether the reward money played any role in Beamud’s capture.

“I can’t answer that right now,” she said.

The FBI has a different spelling of Beamud’s first name, she said, saying they have it listed as Raphael.

An armed robbery carries a maximum penalty of 25 years in prison and a fine of up to $250,000. Beamud is not the first Lowell, Mass., bank robber to get caught after attempting the crime in Maine. Robert Ferguson — who was dubbed the “burly bandit” by the FBI — was caught in July 2010 after robbing 11 banks and credit unions in Massachusetts, Rhode Island, Connecticut, New Hampshire and Orono, Maine, between April and July 2010.

Ferguson, a Greyhound bus driver, wore a mask, sunglasses or hats to hide his identity and was armed with BB guns when he robbed banks along his bus route. He was convicted in federal court in Bangor and in February 2011 was sentenced to 10 years and one month behind bars for the crimes.

The last bank robbery tied to Beamud — the only one in Maine — was reported at about 10:30 a.m. Saturday at the Bangor Savings Bank in York.

“We have been watching things unfold in Massachusetts because we deal with Massachusetts authorities on a regular basis,” LeConte said. “With some of our videos we were able to get a perfect match to a [composite suspect] sketch provided by Massachusetts police.”

The FBI task force included officers from the FBI, federal Drug Enforcement Agency and a dozen police departments, including York Police Department.

“We pride ourselves in working hard to keep open lines of communication with other police departments and this is where it pays off,” the York police captain said.