WELLINGTON, New Zealand — In New Zealand, members of the public are accustomed to seeing their top government officials at the grocery store or on the street, unencumbered by security guards as is more common in other parts of the world.

The country’s prime minister, Jacinda Ardern, even jokingly recounted to Stephen Colbert on the “The Late Show” about being approached by chatty strangers while she shopped for maternity bras.

But on Thursday morning, a government minister was attacked while walking to work alone in the capital city, leading Ms. Ardern to warn that New Zealanders’ unusual level of access to the country’s lawmakers should not be taken for granted.

“We have an environment in New Zealand where politicians are accessible, and that’s something we should feel proud of,” Ms Ardern said. “We are, after all, here to serve people. But today’s events really show we cannot take that for granted.”

The victim, James Shaw, 45, a co-leader of the left-leaning Green Party and the minister for climate change, told the police that he was grabbed and hit in the Thursday morning attack, leaving him with a black eye and cuts on his face. After being treated at the scene, he went on to attend a meeting at Parliament before admitting himself for examination in a hospital, where he remained on Thursday afternoon.

Pete Huggins, a Green Party spokesman, said Mr. Shaw had told the police that his assailant knew his name, although officers have not said whether they believe the attack was planned, or what motivated it.

The episode rattled New Zealand, which Mr. Huggins described as “a very close-knit community and a very open society.”

Unlike in many countries, including the United States and Britain, the prime minister is the only lawmaker accompanied round-the-clock by security personnel; government ministers and other lawmakers are not. Residents of Wellington, New Zealand’s capital, regularly see elected officials walking or cycling the streets alone, and some politicians opt to take public transportation rather than using government vehicles.

“I would hate to see that go,” Marama Davidson, a lawmaker who leads the Green Party with Mr. Shaw, said during a news conference Thursday.

“It would be a shame to lose the way that people can approach us and access us in this country,” she added. “That’s one of the things I value about the way we do politics here in New Zealand.”

The police have arrested and charged a 47-year-old man in the attack on Mr. Shaw. The man, whom the police did not identify, will appear in the Wellington District Court on Friday.

Lawmakers from across the political spectrum joined in condemning the attack. Wellington’s mayor, Justin Lester, wrote on social media that the assailant’s behavior had been “outrageous” and that New Zealanders were “lucky to have unparalleled access” to their elected representatives.