A District man who wore a mask to help rob his grandmother was nevertheless recognized when he spoke up for her during the crime, prosecutors said.

Riley Mercer, 40, was convicted in June in the gunpoint robbery of his grandparents in Northeast. He was sentenced Wednesday to 22 years, prosecutors said.

In 2010, the couple — in their 70s — gave Mercer a house key and a job in their security business, prosecutors said.

In September 2011, Mercer and two others entered the home, and one man led the grandmother to a closet holding a safe. When she moved too slowly for him, the man threatened to shoot her, prosecutors said.

At that point, they said, the grandmother heard: “Don’t hurt her.”

Despite the robbers’ masks, she “was certain it was her grandson’s voice,” prosecutors said.