The U.S. Geological Survey says the quake struck Monday night 200 miles (320 kilometers) southwest of Naha on Okinawa island in southern Japan. Local time was 10:28 p.m. (1328 GMT) at the epicenter, which is around the Ryukyu Islands.
It was at a depth of 22 miles (35.4 kilometers).
The Japan Meteorological Agency issued an alert for a mild tsunami for nearby islands.
There was no immediate report of any damage or injuries.