Two people died of heart attacks attributed to shock from the seismic disturbance, a spokesperson for the public safety ministry told national media.
The quake occurred at 20:28 local (02:28 GMT) on the Central American country's Pacific coast, at a depth of 20km, close to the popular tourist beach town of Jaco, according to the US Geological Survey.
The Pacific Tsunami Warning Centre did not issue a tsunami alert. Several aftershocks were felt.
In the inland capital San Jose, buildings swayed for a couple of minutes. Local media reported that the quake was strongly felt across much of the country.
One network, Channel 6, showed the studio of a sports programme that was live at the time, with the camera and the table shaking. It also showed images of alarmed people running in a supermarket as products fell to the ground.
Officials said minor landslides fell across a coastal road, restricting traffic.
While power was largely unaffected, there were reports of some areas close to the epicentre losing electricity and cellphone transmission.
Media in neighbouring Panama and Nicaragua said the earthquake was felt on their territories too, but no damage was detected.
Costa Rican officials urged citizens to avoid clogging the emergency lines by not calling 911 unless it was to give information about an urgent situation.
"We remind you to remain calm," the presidency said on its official Twitter feed.
KEEP UPDATED on the latest news by subscribing to our FREE newsletter.
- FOLLOW News24 on Twitter