An earthquake with a preliminary magnitude of 5.2 jolted northern and eastern Japan on Thursday, a government agency said.