The quake hit the Pacific Ocean off the coast of Miyagi prefecture at 5:18 p.m. (0818 GMT), the Japan Meteorological Agency said. The epicenter was 10 kilometers (6.2 miles) beneath the seabed and 240 kilometers (150 miles) offshore. So far, there are no reports of serious damage, no fatalities and only two injuries.
The tsunami warning was canceled about two hours after the quake. The Pacific Tsunami Warning Center earlier said there was no risk of a widespread tsunami.
The agency said the area was shaken by repeated, smaller aftershocks.
After the earthquake, officials issued a warning that a tsunami potentially as high as 2 meters could hit. Ishinomaki, a city in Miyagi, reported a tsunami 1 meter (1 yard) high and other towns reported smaller tsunamis.
Video of the shaking was posted to YouTube shortly after the quake hit. People in Tokyo reported high buildings swaying for several minutes.
A sophisticated early warning system gave residents as much as six minutes warning time in advance of the quake.
Japan has barely begun to rebuild from last year's magnitude-9.0 earthquake, which triggered a tsunami that swelled to 20 meters high in some areas, ravaging dozens of coastal communities in Miyagi and elsewhere. About 19,000 people were killed and some 325,000 people remain displaced from their homes, living in barracks and other temporary quarters.
The Associated Press contributed to this report.