Then-Virginia Lt. Gov. Tim Kaine takes aim while shooting skeet in Hardy, Va., before a news conference Aug. 26, 2005. Kaine stressed his outdoors lifestyle and support for the Second Amendment. (Kyle Green/The Roanoke Times via AP)

At his national introduction as Hillary Clinton’s vice-presidential running mate, Sen. Tim Kaine suggested that he has done what few swing-state Democrats have dared: taken on the National Rifle Association.

“I know the NRA,” he said. “They’re headquartered in my state, in Virginia. They campaigned against me in every statewide race that I’ve ever run, but I’ve never lost. . . . I don’t mind powerful groups campaigning against me. That just is like an extra cup of coffee to me.”

But as Kaine hits the campaign trail and makes gun control a central Democratic theme in the 2016 race for the White House, his relationship with the nation’s most powerful gun lobby is more nuanced than the kind of “High Noon” faceoff he suggested.

In more than two decades as a political figure in Virginia, a Southern state with a strong gun tradition and historically lenient firearm regulation, Kaine has pivoted on guns, in style and substance, depending on the political climate, the office he sought and particular events.

He has been an urban mayor determined to reduce gun deaths. And he has been a statewide candidate who embraced the Second Amendment and promised not to tighten gun laws. He has become quiet on the issue at times, and played offense at other moments. As he served in different political roles, in a changing Virginia, Kaine has tailored his stance as the politics surrounding guns have evolved.

At a campaign rally on July 23 in Miami, Democratic vice presidential candidate Sen. Tim Kaine said the Virginia Tech mass shooting in 2007 was "the worst day of my life." Kaine vowed that he and Hillary Clinton will push for "common sense" gun control safety measures if elected into office. (Reuters)

A spokeswoman for Kaine declined to comment for this article.

His current push for more regulation reflects new calculations by Democrats that after years of mass shootings, they can campaign on gun control and win.

“Back before you had these mass shootings that seem to happen every month, running on gun control did not put you in a strong position in a Southern state,” said Wayne Turnage, who served as chief of staff when Kaine was governor. “I don’t think there’s any question the national appetite has shifted.”

Republicans seem just as convinced that, after recent episodes of civil unrest and terrorism at home, Americans who are feeling the need to protect themselves will revolt against any move to roll back gun rights.

“The Second Amendment is on the ballot in November,” said Jennifer Baker, an NRA spokeswoman. Kaine “will be a willing partner in dismantling the Second Amendment,” she added.

Both sides are betting big.

The NRA has vowed to raise up to $75 million for 2016 — almost twice what it spent in 2008. Gun-control groups founded by former New York mayor Michael R. Bloomberg (I) and former congresswoman Gabrielle Giffords (D-Ariz.) also plan to spend millions in battleground states, including Virginia.

When Kaine entered politics in Richmond in 1994, first as a city council member and then as mayor, the city was in the throes of a crack cocaine epidemic and had the second-highest homicide rate in the country. His support for gun control was popular. Yet he stirred controversy in the spring of 2000 when he spent about $7,000 to send eight busloads of Richmonders to the Million Mom March, a gun-control rally in Washington.

Amid criticism that he had used public money for a political cause, Kaine eventually agreed to raise private donations to reimburse the city. Still, he stood firm on gun control.

“There is no issue in the city that is more important than gun violence,” he said at the time. “I can’t think of an issue I’d rather be aligned with than this.”

The next year, when Kaine was running for lieutenant governor, he needed to convince rural Virginia voters that he wasn’t too liberal. He rebranded himself as an outdoorsman who supports the Second Amendment and appreciates guns used for sport. He had camo-style bumper stickers printed. And he played up his role in helping to insert language in the state constitution that guarantees Virginians the right to hunt and fish.

In 2005, when Kaine ran for governor, his website simply declared: “Tim Kaine strongly supports the Second Amendment. As the next governor of Virginia, he will not propose any new gun laws.” He went skeet shooting with Sportsmen for Kaine. He enlisted a rural sheriff to vouch for him in a radio spot.

To his Republican opponent in that race, Kaine’s position didn’t ring true.

“To hear him say it during the governor’s race, he was pro-Second Amendment, no restrictions,” said former state attorney general Jerry Kilgore, who lost to Kaine. “That’s not been his life in public policy. I’ve said all along: He will say anything an audience wants to hear.”

Larry Roberts, who became chief counsel to then-Gov. Kaine, said the 2005 campaign strategy did not rely on the rural vote so much as on the state’s fast-growing, moderate suburbs. Even so, Kaine had to tread lightly on guns, he said.

“Our view was, we needed to win over suburban voters,” he said. “They’re sort of mixed on gun control, even in that time. Clearly, you could not easily win in Virginia if you took the posture of a New York or California candidate on gun control. That would just not have worked in 2005.”

Roberts also said Kaine’s appeal to rural Virginia stressed religious faith more than guns.

“I’m conservative on issues of personal responsibility,” Kaine said in a radio ad at the time. “As a former Christian missionary, faith is central to my life. I oppose gay marriage. I support restrictions on abortion — no public funding and parental consent — and I’ve worked to pass a state law banning partial-birth abortion.”

Today, Kaine supports same-sex marriage. He remains personally opposed to abortion, but says he supports the right of women to terminate their pregnancies.

Kaine has always believed in the right to bear arms, but with limits that made no sense to accentuate in 2005 Virginia because he was already considered too progressive, Turnage said. “He was not willing to add more bricks to that side of the scale,” he said.

Then came Virginia Tech.

On April 16, 2007, not two years into Kaine’s term as governor, the college became the scene of what was then the worst mass shooting in U.S. history. Thirty-three people died, including the shooter.

“As any leader does, he said, ‘It’s time to act,’ ” Turnage said. “He moved his position that you have to more practically interpret the meaning of the Second Amendment against the needs of society.”

In the aftermath of the carnage, a Washington Post poll found that 58 percent of Virginians favored stronger gun control.

Kaine walked away from the pledge he had made as a candidate. He pushed unsuccessfully for a new state law that would require background checks on sales at gun shows. The bill drew fierce opposition from the NRA, which argued that the restriction would not have stopped the massacre at Virginia Tech because the shooter had bought his two semiautomatic handguns from licensed dealers. The bill died in committee.

But Kaine had success on another front — addressing a loophole that had allowed the shooter to buy a gun even though a judge had declared him dangerously mentally ill less than two years earlier. He worked with then-Attorney General Robert F. McDonnell, a Republican, to craft an executive order fixing that loophole. It later won bipartisan support in the legislature. At Kaine’s urging, the General Assembly also provided more money for mental-health services and reformed its civil commitment procedures.

In an interview with The Post last week, McDonnell praised Kaine for focusing on the ­mental-health piece. “I really admired him . . . for not making a political issue out of guns, but really looking at what we could do to really make a difference,” he said.

By the time Kaine sought election to the U.S. Senate in 2012, Virginia was undergoing some profound demographic shifts that reset old assumptions. Rural regions had turned hostile toward Democrats, but Northern Virginia had grown more blue, more developed and more voter-rich.

Kaine concluded that he could win without rural Virginia, as Barack Obama had in 2008.

Yet he steered clear of gun issues in his race against former governor George Allen, a Republican and vocal gun rights advocate with an “A” rating from the NRA. While Allen played up guns on his campaign website, the “F”-rated Kaine, perhaps sobered by his loss in the legislature, was relatively quiet. In the end, like the president on the top of the ticket, Kaine took Virginia — but purely on the strength of its cities and suburbs.

A year after Kaine’s Senate victory, Terry McAuliffe became the first Virginia Democrat to trumpet his “F” rating from the NRA and win the governorship.

In the Senate, Kaine has voted for a series of gun-control bills, including those intended to ban semiautomatic weapons and ­large-capacity magazines. In June, he joined a Senate filibuster to force action on other gun-control bills. Speaking on the floor, he traced his concern about guns to the killing of a Richmond family during his earliest days in politics.

“I got a call as a city council member, and I raced to the scene, and it was chaos,” Kaine said. “And that has begun a 22-year experience of being too intimate with this problem. That funeral of the family in the Arthur Ashe Center in Richmond, with 3,000 people and six little white coffins at the front of the room, is something that I will never, ever forget.”

Those on the other side of the gun debate see a classic bait-and-switch.

“He’s very adept at knowing what to say and how to portray himself when he’s [running],” Allen said. “And then when he is elected, the positions are not consistent.”

Others see a politician adapting to changing circumstances.

“He’s going to flaunt his ‘F’ rating, and he’s probably going to sound more like he did as mayor than he did as governor,” said Bob Holsworth, a political analyst in Richmond. “You could say there’s a change in emphasis.”