The earthquake happened at 11.35am on Sunday in the Pacific Ocean, according to the United States Geological Survey.
Its epicentre was located 23km southwest of Callao, a port city west of the capital Lima.
A 36-year-old man died in northern Lima while "standing outside his vehicle waiting for a passenger" when a wall from the fourth floor of a building under construction detached and fell on his head, Police Colonel Ramiro Clauco told RPP radio.
The five people injured are being treated in hospitals, the Emergency Operations Centre said.
The agency also reported damage to roads and educational centres.
President Dina Boluarte is heading to Callao to monitor developments, the Peruvian presidency said on X.
Footage shared by local media also showed cars hit by falling debris, damaged houses and collapsed billboards.
All of Lima's districts felt the earthquake, Hernando Tavera, executive president of the Geophysical Institute of Peru, told local TV channel N.
Local radio stations reported that a professional football match at Lima's Alberto Gallardo Stadium was paused for several minutes.
A mass at Lima's cathedral was also interrupted after frightened worshippers fled the scene.
Peru is located along the Ring of Fire, a path along the Pacific Ocean characterised by frequent earthquakes and active volcanoes.