SEOUL, South Korea — South Korea’s prime minister was pelted with eggs and water bottles by angry villagers on Friday as he paid a visit to the rural county chosen as the site of a planned United States missile defense system.

The visit by Prime Minister Hwang Kyo-ahn to Seongju, about 135 miles southeast of Seoul, the capital, was meant to defuse continuing opposition to the missile range. Instead, he was forced to retreat as thousands of residents who had gathered in front of Seongju’s government headquarters shouted, “Go away!” according to television footage.

Facing the crowd, Mr. Hwang said South Korea needed the Terminal High-Altitude Area Defense system, or Thaad, to defend against North Korean missiles.

He also apologized for not having explained the rationale for the deployment before the county, which has a population of about 50,000, was named as the site for the missile base on Wednesday.