The Geophysical Institute of Peru (IGP) said the temblor struck at 04:35 (09:35 GMT) and had an intensity of III on the Modified Mercalli scale in Huacho and III-II in the capital Lima.
The quake's epicenter was offshore at 40 kilometers (24.8 miles) south of Huacho with a depth of 69 kilometers (43 miles).
According to Civil Defense authorities, no damage or injury has been reported so far from the quake.
Huacho, capital of the Huaura province, is situated 149 km (92 miles) north of Lima. Peru is in the "Pacific Ring of Fire," which is the site of 85 percent of global seismic activity.