The country's Public Safety Ministry said there were reports of two serious injuries as a result of the quake, but did not provide additional details.
Electricity was knocked out in some areas as power lines and poles fell, but there were no reports of major infrastructure damage from the tremor, which hit in a lightly populated area on the Pacific Coast. The government reported some rockslides obstructing highways near the epicenter.
The U.S. Geological Survey said the earthquake was centered about 10 miles (15 kilometers) southeast of the town of Jaco, which is about 60 (100 kilometers) miles southwest of the capital, San Jose. The quake was at a depth of about 12 miles (20 kilometers).
Magdalena Lopez, who lives in Jaco, said the tremor started softly, but quickly strengthened.
"When we were trying to get out of the house it started to shake again very strongly," she said. "All of our neighbors were in the street. In front of my house there is an overlook some people started to go up, but it quickly started to shake again."
Four minutes after the initial earthquake, a magnitude 5.2 aftershock struck.
President Luis Guillermo Solis said via Twitter that the government was still gathering information. He urged people to remain calm and prepare for aftershocks.