Updated

President Obama has taken the rare step of inserting himself into a local legislative contest in Illinois, cutting an ad for a challenger who is competing against an incumbent Democrat known for siding at times with Republicans.

In a 30-second television ad, Obama says he’s learned from his days in the state legislature that “follow-through is everything” and therefore is throwing his political weight and endorsement behind Juliana Stratton over Rep. Ken Dunkin of Chicago.

Obama says he’s backing Stratton because she will “stand up for our children, our seniors and our working families.” He says Stratton will fight for gun control and tougher penalties for violent offenders.

But there likely are other factors at play, in what is shaping up as one of the nastiest and toughest political battles in Illinois.

Dunkin has sided with Republicans during key votes -- denying House Speaker Michael Madigan what would otherwise be a 71-vote veto-proof majority -- and has received campaign contributions from allies of Republican Gov. Bruce Rauner.

Stratton, by contrast, is backed by unions and has picked up the support of almost all the other prominent Democrats in the state.

There has been bad blood between Obama and Dunkin for years.

During a February visit to Springfield, Ill., Obama riled up the lawmaker when he said reaching across the aisle for the sake of compromise “doesn’t make me a sellout to my own party.”

Dunkin jumped out of his seat and interrupted the president by shouting “Yes!”

Obama snapped back, “We’ll talk later Dunkin. Sit down.”

Chicago Mayor Rahm Emanuel told WLS-AM News that Obama’s endorsement is about getting lawmakers to work together and end the Illinois budget deadlock.

“It’s not a political endorsement. It’s an endorsement to move forward and finally get the city and the state, most importantly, moving forward,” he said.

On Monday, Sally Daly, a spokeswoman for Cook County’s State’s Attorney Anita Alvarez, said her office is “looking into” a complaint against Dunkin that alleges his office paid voters.

A spokesman for Dunkin told the Chicago Tribune the accusations are “baseless.”

While a rarity, Obama has endorsed other local candidates in the past. In 2014, he announced his endorsement of now-D.C. Mayor Muriel Bower. Obama’s endorsements of Bill de Blasio of New York, Annise Parker of Houston and Mitch Landrieu of New Orleans may have helped all three clinch victories.