The earthquake rocked Okinawa and several smaller islands in southwestern Japan on Monday morning. There were no immediate reports of casualties or damage.
A tsunami warning was issued for the area, instructing coastal-area residents of the islands to move to higher ground.
The meteorological agency said the tsunami, a large wave generated by undersea earthquakes, could reach a height of seven feet.
Scientists say the earthquake was centered at a depth of 12 miles under the seabed, 160 miles south of Ishigaki Island.
Ishigaki is one of the islands in Japan's southernmost prefecture of Okinawa, about 1,000 miles southwest of Tokyo.