Peru’s Geophysical Institute (IGP) said the quake struck at 13:40 local time (18:40 GMT) with its epicenter 58 kilometers (36 miles) west of the port city of Callao.
The IGP reported that the tremor had a depth of 40 kilometers (24.8 miles) and an intensity of III and IV on the Modified Mercalli scale.
There were no immediate reports of injuries or damages from the quake, which was the second to hit the Peruvian capital this week after a magnitude-4.0 tremor shook downtown Lima on Monday.
Earlier today, a magnitude 4.1 earthquake hit northern Peru about 71 km south-east of La Libertad's Trujillo province, at a depth of 43 km.
Peru is located in an area known as the Pacific Ring of Fire, where about 85 percent of global seismic activity occurs.