He is a Baptist minister who opposes gay marriage, a Republican who is critical of his party’s leaders in Congress, and a candidate who ran a shoestring campaign against a House incumbent. And on Wednesday, Mark Harris found himself in another role: A giant-killer of the 2018 midterm elections.

Mr. Harris beat Representative Robert Pittenger in a Republican primary in North Carolina on Tuesday, making Mr. Pittenger the first incumbent from either party to lose his seat in Congress due to a primary challenger this year.

House Republicans were already concerned about Mr. Pittenger’s chances against the well-funded Democratic nominee, the Iraq war veteran Dan McCready, but believed he would fend off the challenge from Mr. Harris, who instead beat him by fewer than 1,000 votes.

“People are catching on to that ‘drain the swamp’ thing, and I think that is a message we have to consider,” Mr. Harris said in a telephone interview on Wednesday. “Is it fair to say the establishment was surprised by what happened last night? Definitely so.”