A man who robbed a house in Casco before dawn Tuesday forgot his gun when he left, then forgot to hide his identity when he went back to get it, letting the residents he had tied up recognize him, police say.

The Cumberland County Sheriff’s Office says Dylan McPhee got away, but not for long.

At 1 p.m., he and a suspected accomplice were stopped by Massachusetts State Police on Interstate 90 in Sturbridge and arrested in connection with two armed home invasions. A third suspect was arrested in Fryeburg late Tuesday afternoon.

“I’m glad some of the people we deal with aren’t the brightest bulbs, because they make our jobs easier,” said Sheriff’s Capt. Don Goulet.

McPhee, a 20-year-old Gray resident, and his girlfriend, Olivia Patricia Pope, 19, of Conway, N.H., face extradition from Massachusetts back to Maine. Merwan Machhout, 21, of Fryeburg is charged with robbery and is being held in the Cumberland County Jail in Portland, pending a court date.

The sheriff’s office said two men and a woman forced their way into a home on Brown Avenue in Casco at 3 a.m. Tuesday.

The woman knocked on the door and said she needed help. When the elderly homeowner opened the door, two men with handguns, one of them wearing a mask, forced their way inside.

A nephew of the victim, who lives in an apartment attached to the house, heard screaming and called 911. The intruders knew the call had been made, and fled.

The three then drove to a home on New Road, about a half-mile away, where the woman told the residents she needed help. The three forced their way inside and confronted the residents, a man and a woman.

The man was hit on the head with the grip of a handgun, then the two were tied up and gagged with duct tape. At one point, a gun was pointed at the man’s face, police said.

Over a span of close to two hours, the suspects stole prescription drugs, a wedding ring and other jewelry, along with a flat-screen television and other electronics.

McPhee, who wore a scarf to cover the lower half of his face, put down his semi-automatic handgun while he hauled stolen items to the car, police said. He went back in to look for his gun, but forgot to put the scarf back on, Goulet said.

The residents recognized McPhee, whose mother is a friend of theirs, police said.

When McPhee couldn’t find his gun, he took a rifle belonging to the homeowners, police said.

The residents eventually freed themselves and called sheriff’s deputies about 5:30 a.m. The man was taken to Bridgton Hospital, where he was treated and released, police said.

After releasing McPhee’s photograph, the sheriff’s office got phone calls from members of his family who provided leads, including the possible identities of McPhee’s accomplices, police said.

Family members were afraid that McPhee’s crime spree could get him shot, Goulet said.

With help from Conway and Fryeburg police, investigators identified the woman as McPhee’s girlfriend, and got a description of their black Chevrolet Aveo and information that they were going south, he said. That led to their arrest in Massachusetts.

Fryeburg police staked out Machhout’s house on Tuesday. He told his mother he was in a class and would contact his lawyer and turn himself in, but police arrested him at the house a short while later.

McPhee has an outstanding arrest warrant for violating bail conditions stemming from an earlier weapons charge, police said.

Goulet said the homeowners’ terrifying experience should be a warning to make people cautious.

“There’s good and bad about living in Maine. The good is, we don’t normally see this stuff,” he said. “The bad is, over the last few years, we see a little more of these big-city crimes.

“People do have to be conscious of their surroundings and make good choices,” he said. “Someone knocking on the door at 3 a.m. is not the norm. I recommend if there’s any questions, before someone would open the door they call police, 911.”

David Hench can be contacted at 791-6327 or at:dhench@pressherald.com