Two people were killed after a powerful earthquake rocked parts of Peru and neighbouring Ecuador, with more than 30 people injured, authorities said.

The 8.0-earthquake hit a sparsely populated region of Peru's Amazon basin region but was felt over a wide area.

Reports were still coming in from remote areas affected by the quake, which also rattled the capital Lima and other cities where frightened residents rushed into the streets.

A teenage boy was killed after being struck by falling masonry in Peru's northern region of La Libertad.

The other victim, a 48-year-old man, was reported to have been killed by falling debris while he slept at his house in Cajamarca in northern Peru. 

The quake was the most powerful to hit the earthquake-prone country in 12 years, Peru's President Martin Vizcarra said, adding that it blocked roads, damaged a bridge and knocked down houses.

"It is an earthquake affecting the entire Peruvian jungle," he said.

One of the most dramatic moments captured on social media happened in Yurimaguas, the town closest to the epicentre.

Video from the police station shows the police chief shouting at his subordinates to quickly open the jail cells and get inmates outside.

"The earthquake is strong!" he is heard yelling. "Open the cells! Help with the detainees, get one each!"

Arri Pezo, the mayor of Lagunas, 75km from the epicentre, said many residents who fled from their homes later stayed in the streets for fear of aftershocks.

Reports said 15 people had been hurt in Ecuador, where power-cuts were reported in parts of its Amazon basin region. Peruvian media said the tremor was also felt in parts of Colombia and Venezuela.

Peru lies on the so-called Ring of Fire - an arc of fault lines that circles the Pacific Basin and is prone to frequent earthquakes and volcanic eruptions.

The South American country records about 200 earthquakes a year, most of them going unnoticed by the public.