A 9-year-old Idaho girl died this week after falling from a tree and impaling her head on a steel bar, but saved four lives and a stranger’s vision through organ donation, her mom said.

Shaylyn Bergeson died “very comfortable and quickly” at a hospital in Utah late Thursday after impaling the left side of her head on a piece of rebar as she played in her back yard near Rexburg on Monday.

“Our baby was able to save four lives and someone’s vision,” Bergeson’s mother, Jesi, posted on Facebook. “The transplant team was able to retrieve her liver, kidneys, heart valves and corneas.”

The freak accident has sent the girl’s family spiraling into an emotional whirlwind, leaving them simultaneously “completely devastated” and “so proud and overjoyed” for the people Shaylyn helped in her final moments, Bergeson said.

Doctors removed half of the girl’s skull to relieve pressure inside her brain, and gave her a 50 percent chance of surviving the craniotomy, Bergeson told EastIdahoNews.com.

Earlier Thursday, Bergeson said she and her husband, Kurt, were preparing for their “sweetest, kindest and most selfless” daughter to succumb to her injuries. They decided to consider donating her organs after having a discussion with her months earlier, Bergeson said.

“We have been so blessed with the absolutely best medical team during all this and they are still providing the best care to make sure she is respected, honored and comfortable as we allow her to pass and continue to give life to another lil kiddo,” she wrote.

Bergeson also asked for prayers as she and her husband prepared to bury a child for the second time. Shaylyn’s sister, Briauna, died from a rare chromosome abnormality in 2016. She was just 10 years old.

“We are not doing good right now,” Bergeson told EastIdahoNews.com prior to Shaylyn’s death. “We lost her older sister just four years ago and the thought of losing another baby is tearing us up.”

Fremont County Sheriff Len Humphries, who responded to the family’s home on Monday, said Shaylyn’s parents had reported her missing earlier that day. One of several officers who responded to the home with him later found her unconscious with a piece of rebar protruding from her head, Humphries said.

“It was very obvious that she was seriously injured,” Humphries told The Post. “We had to cut the rebar that was holding her.”

The piece of steel that was sticking out of the ground impaled the back of the girl’s skull and pierced her brain, Humphries said.

“It was a tragic accident,” the sheriff said. “Totally, totally freak — I’ve never heard of anything like this before. She was a beautiful young girl. I feel for the family.”

Shaylyn was set to start fourth grade at Kershaw Intermediate School in Sugar City next month. An online fundraiser set up in her memory had exceeded $17,000 as of Friday. Her father said he was struggling to understand why tragedy had once again befallen the family.

“Why did this happen? What could I have done to stop this?” Kurt Bergeson wrote on the website. “The only explanations I can think of are that we are not meant to understand why at this time, only God understands.”