A powerful earthquake has rocked Costa Rica, killing at least two people, sparking landslides, knocking down buildings and briefly triggering a tsunami warning.

Residents of the capital San Jose said phones went down, electricity poles rattled on the streets and water flowed out of swimming pools after the 7.6 magnitude quake.

The Red Cross said two people died. One was a man working on a construction site who was killed when part of a wall fell on top of him. The other was a woman who suffered a heart attack.

Costa Rican television said 22 people were also treated for injuries. The Red Cross could not confirm this.

Locals were shocked by the force of the earthquake, which was felt as far away as Nicaragua and Panama, and the biggest to hit Costa Rica since a 7.6 magnitude quake in 1991 left 47 dead.

Esteban Moreno, a spokesman for the national emergency services, said some buildings near the epicentre in the Pacific region of western Costa Rica had collapsed, though he added they were mostly older, and of poor structural quality.

There were local reports of the earthquake leaving its mark on hotels in the region, though Moreno said he was unaware of any serious damage suffered by tourist resorts.

The CNE said landslides had blocked some roads and that damage was done to some homes in built-up areas in the Nicoya Peninsula on the Pacific coast.

The Pacific Tsunami Warning Center initially issued a warning for Pacific coastlines of Costa Rica, Nicaragua and Panama, but this was later cancelled. The centre had earlier warned of tsunamis for as far afield as Mexico and Peru.

The epicentre was in western Costa Rica about 140km from San Jose, the US Geological Survey said.

The Guanacaste region around the epicentre is known for its beaches, surf and volcanoes. With several nature and marine reserves it is less tropical than the rest of the Central American nation, with stretches of open savannah and mountains.

The last serious quake to hit Costa Rica was a 6.1 magnitude quake in January 2009, which killed 40 people.