Updated at 9:38 p.m.

In a surprise move, Rep. Steve Stockman (R-Tex.) filed papers to challenge Sen. John Cornyn (R-Tex.) at the last minute Monday, giving the second-ranking Senate Republican a potentially tough primary opponent just as he looked poised to avoid one.

Texas Republican Party spokesman Spencer Yeldell told Post Politics that aides to Stockman withdrew his application for reelection to the House and switched to the Senate race shortly before the filing deadline arrived on Monday.

"The filing period ended at 6 [p.m.] and it was a little before then," Yeldell said. Stockman's team made the change in person at the Texas Republican Party headquarters in Austin, Yeldell explained. The congressman was not present for the filing.

Stockman is known for his controversial statements and far right political views. He threatened earlier this year to try to impeach President Obama over gun regulations.

The congressman was one of seven Republicans including Cornyn who filed for the Senate primary, which will be held March 4, 2014. A candidate must claim a majority of the vote to avoid a runoff.

Stockman's decision means that seven of the 12 Republicans who are running for reelection are facing credible or at least quasi-credible primary challenges.

The congressman will be a decided underdog to Cornyn, but he presents a bigger threat than anyone else in the GOP field.

His decision to make a Senate bid caught observers by surprise Monday. Local and national tea party groups had all but written off a serious effort to unseat Cornyn, who looked like a potential target for a conservative challenge earlier this cycle, but tacked to the right this year in an effort to avoid a challenge of any note and appeared poised to avert one.

“There is nothing going on in this race,” Julie McCarty, a leading Texas tea party activist told The Washington Post in November.

When asked for a reaction to Stockman's decision, Cornyn's campaign pointed to the senator's record and did not mention the congressman.

“Endorsed by Texas Right to Life and ranked as the 2nd most conservative Senator in America, Senator Cornyn looks forward to discussing his conservative record with Texans," Cornyn campaign manager Brendan Steinhauser said.

The conservative Madison Project didn't commit to backing any of Cornyn's challengers Monday, but welcomed "news of a primary challenge"  in a statement that slammed Cornyn.

"As Minority Whip, Senator John Cornyn's main job is to unite 41 votes against liberal legislation. On issue after issue, Cornyn has failed to whip votes against the Democrats, effectively handing Senator Harry Reid a supermajority," said Daniel Horowitz, the group's policy director. "Texans are starving for two fighters, and news of a primary challenger is quite welcome."

Stockman qualified for the primary by paying a $5,000 registration fee, Yeldell said. Senate candidates have the option of paying a fee or submitting signatures.