Devon Staples of Calais, Maine, was in a friend's backyard with a group of others when the incident occurred.
The explosion caused a fatal head injury, and Staples died instantly, said Stephen McCausland, spokesman for the Maine Department of Public Safety.
Staples had been drinking with his friends when the incident occurred, McCausland said.
"When he suggested he was going to do this, his friends gathered around him and they thought they had convinced him not to do it," McCausland was quoted as saying by Bangor Daily News.
More From This Section
His brother Cody Staples told the New York Daily News that he was standing five feet away from Devon in the backyard. He said his brother was holding a lighter and it accidentally caused the firework to go off.
"I was the first one who got there. There was no rushing him to the hospital. There was no Devon left when I got there," his brother said.
"It was a freak accident...But Devon was not the kind of person who would do something stupid. He was the kind of person who would pretend to do something stupid to make people laugh," he said.
The incident was among several Fourth of July fireworks mishaps reported. In Lincoln, a garage was damaged when remains from expended fireworks ignited.