A 66-year-old man saved his grandson from the grip of a 16-foot-long anaconda by beating the snake with rocks and a knife for half an hour, authorities said Thursday.

"When I saw the snake wrapped around my grandson's neck I thought it was going to kill him," Joaquim Pereira told Brazil's Agencia Estado news service. "It was agonizing, I pulled it from one side, but it would come back on the other."

Pereira's 8-year-old grandson, Mateus, was attacked by the anaconda while wandering near a creek on his grandfather's ranch in the city of Cosmorama, about 250 miles northwest of Sao Paulo.

While the boy was playing with friends, the snake attacked and wrapped itself around him, police officer Hudson Augusto said. Anacondas are not poisonous, but kill their prey by coiling around them and squeezing until victims suffocate.

"It brought me to the ground and bit me," the boy told Globo TV. "Then it started crawling up my neck and began suffocating me."

Mateus' friends ran to get his grandfather, who reached the scene and battled with the snake until he had hurt it so badly that it let go of his grandson.

Mateus had to be rushed to a hospital and needed 21 stitches on his chest where he was bitten. He was later released.

Globo TV showed footage of the dead snake, which weighed about 77 pounds. Police said anacondas are not uncommon in the region where the attack occurred, but attacks on people are rare.