ROME — Pope Francis was making his way through a New Year's Eve crowd in St. Peter's Square on Tuesday, smiling and clutching hands with well-wishers. Then, just as he was turning away, a woman caught him by surprise — and got a glimpse of an aggravated pope.

The woman grabbed Francis’s right hand and pulled him toward her. The startled pope smacked the woman’s hand as a way to break free, a reaction he apologized for Wednesday.

Video showed Francis with a disgusted look as he walked away.

In an address to pilgrims a day after the incident, Francis diverted from his scripted remarks upon the mention of patience.

“So many times we lose our patience; me too, and I apologize for yesterday’s bad example,” Francis said.

The woman was not immediately identified. She, like others in the crowd, was separated by a white barrier from the pontiff, who was proceeding through the square along with a team of security and lieutenants. The woman had crossed herself as the pope moved slowly in her direction. As she pulled the pope toward her, she also said something to Francis that was not easily decipherable.

The pope regularly finds himself in the middle of adoring throngs, both at the Vatican and during overseas visits. During his papacy, it has been rare for Francis to show annoyance with the behavior of crowds, though certain moments have set him off.

During a trip to Mexico in 2016, somebody in a crowd pulled on the pontiff’s arms, causing him to keel over atop a person in a wheelchair. Francis gestured angrily afterward, saying, according to the Catholic News Service: “What is the matter? Don’t be selfish!”

Last March, video showed Francis repeatedly pulling his hand away from well-wishers trying to kiss his ring. Some conservative Catholic media outlets criticized the pope for being so averse to a traditional sign of respect. A Vatican spokesman later said Francis was concerned about hygiene.

“He wants to avoid the risk of contagion for the people, not for him,” the spokesman said.

Over the years, popes have faced a number of unpredictable encounters with crowds — in a few cases, far more dangerous than the incident Tuesday. In 2009, a woman jumped a barrier and lunged at Pope Benedict XVI, knocking him to the ground. The woman was later identified as a Swiss-Italian with a history of mental problems who had tried a similar attack a year earlier, only to be stopped by security guards. The Vatican said it would review security procedures after that.

Francis has kept a busy schedule over the holidays, with regular events inside the Vatican. Before apologizing Wednesday for the smack, he delivered a homily on the topic of women, denouncing “every form of violence” they face, including rape, forced prostitution and verbal abuse.

“We can understand our degree of humanity by how we treat a woman’s body,” the pope said.