Republican Joni Ernst became the first woman from Iowa elected to Congress on Tuesday as she prevailed over Rep. Bruce Braley (D., Iowa) in a closely fought Senate race.

Ernst, a state senator and Iraq War veteran, was projected to win retiring Sen. Tom Harkin’s (D., Iowa) seat. The Republican defeated Braley, a four-term congressman and former trial lawyer, in a race that went down to the wire and provided crucial help to the GOP’s retaking of the Senate majority.

Braley began the race with an advantage due to his name recognition as a congressman, but a series of missteps quickly changed the dynamic of the contest. A video surfaced earlier this year of Braley calling popular Sen. Chuck Grassley (R., Iowa) a "farmer from Iowa who never went to law school"—comments that many viewed as elitist in a state with more than 90,000 farms.

Subsequent reports revealed that he posted a picture of an English fruit farm to his Facebook page—rather than an Iowa farm—and threatened to sue his neighbors over chickens that wandered into his vacation home’s yard.

The race tightened considerably after Ernst won the June primary for Republicans by a significant margin. Ads that mentioned her youth spent "castrating hogs on an Iowa farm" and depicted her riding motorcycles and shooting guns went viral and gave her national prominence.

The key perceptions that developed in the race—that Braley was out-of-touch with farmers in the state while Ernst was one of their own—aided the Republican’s victory. The final Des Moines Register poll for the race found that likely voters regarded Ernst as a candidate who better reflected Iowa values and cared more about people like them. Democrats have typically polled better on the latter category.

Braley was also hurt by his record of missing more than 75 percent of the full House Veterans’ Affairs Committee hearings in 2011 and 2012, a statistic that the GOP trumpeted early and often.

Additionally, national security became an issue in the race as a spate of foreign crises lowered public approval for President Barack Obama’s administration. Ernst frequently reminded Iowans that her "boots were on that ground" in Iraq as she criticized Braley for voting to restrict any funds for combat operations in that country against the Islamic State (IS) terrorist group.

Braley later said he supported U.S. airstrikes against IS in Iraq and Syria but mischaracterized his vote for a program to train and equip moderate Syrian rebels.

Sen. John McCain (R., Ariz.), a leading hawk on national security issues in the Senate, previously said on the campaign trail that Ernst would join him in the chamber as an advocate for a robust U.S. foreign policy. Ernst is the first female combat veteran elected to the Senate.

Records show that Republicans in Iowa significantly improved their ground game efforts in this year’s election. As of Monday, Democrats had returned about 8,000 more absentee ballots than Republicans, compared to an advantage of about 19,000 for Democrats on the eve of the 2010 election.