For an Italy worn out after a year that included deadly earthquakes, political turmoil and a slow-motion banking crisis, the news that two Italian police officers helped stop one of the world’s most wanted terrorists came as a relief.

The officers — Cristian Movio, 36, and Luca Scatà, 29 — were on patrol in the small city of Sesto San Giovanni around 3 a.m. Friday when they came upon a man walking alone next to a subway station that is the northern terminus for one of the lines that take commuters to and from Milan.

They had no idea that the man was Anis Amri, 24, the chief suspect in the truck attack in Berlin on Monday that killed 12 people and injured nearly 50. The officers asked him for identification. When he responded in Italian that he had no documents on him, they asked him to empty his pockets and backpack. Mr. Amri then pulled out a pistol and opened fire, shooting Officer Movio in the shoulder. Officer Scatà returned fire, killing Mr. Amri.