A powerful offshore quake triggered panic among residents and tourists after shaking buildings and sending people into the streets.