Tonga was rocked by an earthquake that could cause hazardous waves on its coastline.