SEOUL, South Korea — North Korea carried out one of its most provocative missile tests in recent years early Tuesday morning, hurling a ballistic missile directly over Japan that prompted the government in Tokyo to warn residents in its path to take cover.

The missile flew over the northern island of Hokkaido and landed harmlessly in the sea, after a flight of nearly 1,700 miles. But the propaganda value for the North Koreans was considerable.

Public television programs in Japan were interrupted with a rare warning screen announcing the missile’s flight over the country. Several bullet train lines were temporarily halted, and the government spoke of the missile — only the third North Korean projectile to fly over the country since 1998 — in unusually dire terms.

“North Korea’s reckless action of launching a missile that passed over Japan is an unprecedented, serious and grave threat,” said Japan’s prime minister, Shinzo Abe. He later told reporters that he had spoken by telephone with President Trump. “Japan and the U.S. stances are completely matched,” he said, adding that they discussed ways to tighten pressure on North Korea.