CHARLOTTE, N.C. — Panthers defensive end Jared Allen decided to ride off into the sunset — well, sort of.

Allen, a four-time All-Pro who played 12 seasons in the NFL and twice led the league in sacks, announced his retirement from football on Thursday in his own unique way — sitting atop his horse.

A self-described cowboy who was raised on a ranch, Allen thanked everyone in a short video he released on Twitter before smiling and saying, “I was going to ride off into the sunset, but seeing there is no sunset I’m just going to ride off.”

He then turned the horse to the camera and they galloped away into the dark, gray night.

Allen, 33, finished his career with 136 career sacks — ninth-most in NFL history. He led the league in sacks in 2007 and 2011.

Allen’s retirement did not come as a surprise. He was due to make $8.25 million under the 2016 salary cap and it was highly unlikely the Panthers would have paid him that salary.

advertisement | advertise on newsday

Allen played four seasons for the Kansas City Chiefs before being traded to the Minnesota Vikings, where he spent the next six years. He played two full seasons with Chicago before joining the Panthers early in the 2015 season in a trade.

“I want to take this time to thank my family, friends, fans, and teammates who have given their continued support throughout my 12-year career,” Allen said in a statement on the team’s website. “It’s been a great ride for me, and I couldn’t be more grateful for the memories. It is with a great deal of thought and consideration that I have decided that I will not return to football next year.

“I want to thank the Carolina Panthers, Chicago Bears, Minnesota Vikings and the Kansas City Chiefs organizations, who provided me with an opportunity to live out my dream and to be a part of their wonderful communities. Thanks for the lifelong memories.”

Panthers general manager Dave Gettleman could not be reached for comment, but he had hinted two days after the season that Allen might retire.

The Panthers acquired Allen from the Bears three weeks into the season, allowing him to return to playing in his more natural role 4-3 defensive end. The Bears had switched to playing a 3-4 defensive scheme after the 2014 season and he said it simply wasn’t a good fit.

NFL videos

Allen started 12 games and recorded 25 tackles, two sacks and 16 quarterback pressures for Carolina.

He didn’t play in the team’s NFC championship game win over the Arizona Cardinals because of a broken bone in his foot, but returned to play in his first Super Bowl — a 24-10 loss to the Denver Broncos.

Allen will be remembered for his pass rushing abilities.

His best season game in 2011 when he posted a career-high 22 sacks with the Vikings.