Earnhardt announced Tuesday that he will retire at the end of this season, a decision that will cost NASCAR its most popular driver. (Chuck Burton/AP)

Regardless of the playing field, regardless of the stature of the champion, it is the last act of a career in professional sports that is most difficult to master. How does an athlete know when to quit? How does he recognize that dreaded sweet spot, just before the joy is lost and before time and age, in their inexorable way, start chipping away at a legacy?

With Tuesday’s announcement that he’ll retire at season’s end, NASCAR’s Dale Earnhardt Jr., 42, got it right, executing the tricky final turn of a high-risk career.

“It’s really simple: I wanted the opportunity to go out on my own terms,” Earnhardt said, alluding to the third diagnosed concussion of his racing career — one that sidelined him for the second half of the 2016 season.

As he grappled with his months-long recovery, Earnhardt told reporters, he confronted the possibility that his racing career could end “without me so much as getting a vote at the table.” And in that span of time — time he wasn’t accustomed to having — he said he came to understand what was truly important: the love and support of his longtime girlfriend and now wife; the support of his teammates, family and friends; and the opportunity to recover to the point that he could regain “some semblance of say-so” about his career’s end.

Dale Jr. with his father in February 2001 shortly before he died in a crash in the final lap at the Daytona 500. (Amy Conn/AP)

His decision made, Earnhardt will bow out after 18 seasons in stock-car racing’s elite ranks. Excluding what success is in store in the 28 races that remain on the 2017 Cup schedule, his career record will stand at 26 wins, including two Daytona 500 victories, but no NASCAR Cup championship.

If there was a loser in Tuesday’s announcement, it was NASCAR.

Earnhardt is the sport’s third star to retire in the last two years, following four-time NASCAR champion Jeff Gordon in 2015 and three-time champion Tony Stewart last season.

Meanwhile, TV ratings and race-day attendance are on a decade-long slide. The erosion started when NASCAR’s third-generation owners abandoned many of the sport’s traditional Southern short tracks in favor of gleaming superspeedways built in major markets such as Los Angeles and Las Vegas. They opened corporate offices in Hollywood and New York. And they learned, too late, that they’d alienated their core fan base.

That estrangement — with NASCAR “getting above its raising,” in Southern vernacular — combined with a downturn in the economy led to a drop in attendance. Track owners removed seats in response, hoping to drive up demand. But seats sat vacant, while TV ratings dropped from double-digits to the 5.6-6.6 range.

To jazz up the competition, NASCAR officials modified their playoff format multiple times. Still more drama-inducing changes were unveiled on the eve of the 2017 Daytona 500, but a sobering story in the Wall Street Journal documented the economic and demographic factors behind its waning popularity, declaring “NASCAR, Once a Cultural Icon, Hits the Skids.”

Stock-car racing’s appeal has never resided in the rule book. Nor is it under the hoods of the racecars. It resides in the drivers. NASCAR has always been driven by the cult of personality. And that’s why the retirement of Earnhardt is so profound. Even before Tuesday’s announcement, former Charlotte Motor Speedway president H.A. Humpy Wheeler had been scanning the current crop of drivers, looking for the next generation’s star.

“I haven’t seen it yet,” Wheeler, regarded as the sport’s greatest promoter, said in a telephone interview Tuesday. “To find out about NASCAR, you have to go to the small towns of the South, to the mountains of Appalachia. I go to those places, and I hear what they have to say. They’re not as enthused as they were. They’re looking for another [Dale] Earnhardt Sr.,” Earnhardt’s legendary father who died on the last lap of the 2001 Daytona 500.

[Archives: Liz Clarke on the day Dale Earnhardt Sr. died]

The achievements of Dale Jr. extend far beyond the track, starting with the way he responded to his father’s death 16 years ago. Earnhardt’s achievements extend to the young drivers he has mentored to take his place in the spotlight. And they extend to the decision he made without fanfare in April 2016, before his last concussion, to donate his brain for scientific research on the effects of concussions.

Earnhardt’s father was NASCAR’s most polarizing figure through the 1980s and ’90s. Worshiped as a workingman’s hero by half the fans and reviled as a bully by the rest, he was reason enough to buy a ticket. And when he died at 49, it was his son who bore fans’ grief.

“He had the world by the tail and was just an incredible talent with unlimited potential,” former racer Kyle Petty recalled of Dale Jr. in a telephone interview. “So many fans, so many people, projected their loss and their emotions, their hopes, their aspirations, their dreams and their shattered dreams all on him. And he had to shoulder all and carry all that. It made him who he is today.”

Earnhardt raced the Sunday after his father’s death. And he raced the rest of the 2001 season, sublimating his own grief so he could absorb that of legions of fans he’d never meet.

From that moment, the son became NASCAR’s biggest star. Not because he was his dad’s twin or some lesser, Dale-Lite version. Even as a teenager trying to make his way in racing, Earnhardt was his own man, with his own taste in music and bleached streaks in his auburn mop of hair. But if he was a stock-car racing hipster, he was an old soul, too — well-schooled in great racers of old, with respect for NASCAR’s storied racetracks, a deep love of the grease and high-octane gas that made 800-horsepower engines go and an unabashed affection for the sport’s fans.

[Earnhardt says he wanted to retire ‘on my own terms.’]

He didn’t see himself as better than ticket-buyers. Although he was given a famous name, there was little fortunate about his early upbringing. He was packed off to military school by an absentee father trying to race his way out of debt, given an entry-level job changing oil at his dad’s Chevy dealership and, as a youngster on the minor-league circuit, expected to rebuild every car he tore up.

“Dale Jr. wasn’t the boy next door. He was the farm-boy next door,” Wheeler said. “We needed that because NASCAR had gotten away from our roots, and that hurt us badly in some ways. With his father’s demise, we needed an Earnhardt badly. He was a breath of fresh air when we really needed it.”

Today, Dale Earnhardt Jr. is many things. In addition to being named NASCAR’s most popular driver each of the past 14 years, he is a newlywed, married this past New Year’s Eve. He owns a bar and nightclub, Whisky River, in Charlotte. And while he races for the powerhouse Hendrick Motorsports, he and his sister, Kelley Earnhardt Miller, have owned and operated their own stable of NASCAR teams that compete in the second-tier Xfinity Series, which has served as a finishing school for young racers, for the past 16 years.

It’s through JR Motorsports that Earnhardt has nurtured rising NASCAR stars such as Brad Keselowski and Chase Elliott.

Stock-car racing will need those young talents going forward.