A magnitude 5.9 earthquake struck Costa Rica's Pacific coast with tremors felt in the town of Quepos and northern Panama.