An earthquake with a preliminary magnitude of 6.8 struck off the coast of Costa Rica on Sunday night, the US Geological Survey (USGS) said.