GREAT FALLS, Mont. — President Trump lobbed personal and derogatory attacks at two Democratic senators, mocked the #MeToo movement and vouched for President Vladimir V. Putin of Russia on Thursday during a freewheeling, raucous rally ostensibly intended to solidify support for Montana’s Republican Senate candidate.

Taunting Senator Elizabeth Warren, Democrat of Massachusetts, with a refusal to apologize for calling her “Pocahontas,” Mr. Trump imagined a debate during which he would gently throw an ancestry testing kit at Ms. Warren to make her prove the Native American heritage she has controversially claimed.

“We are going to do it gently because we’re the #MeToo generation, so we have to be very careful,” the president said to scattered laughter, adding that he would donate $1 million to charity if Ms. Warren followed through. Mr. Trump, who has faced accusations of sexual assault and harassment, announced earlier in the day that Bill Shine, who was ousted from Fox News over his handling of the network’s harassment scandals, would take a position on his administration’s communications staff.

Mr. Trump was in Montana, he unabashedly told the crowd, to settle a political score with Senator Jon Tester, a Democrat who is tangled in a tough re-election campaign with Matt Rosendale, the state auditor. The president blamed Mr. Tester for the failed nomination of Dr. Ronny L. Jackson as head of the Veterans Affairs Department because he raised concerns about Dr. Jackson’s professional conduct.