In a rare primary election outcome in Michigan’s Eighth Congressional District, Tom Smith, a small-business owner from Flint who had previously suspended his campaign, defeated Amir Hassan, a Navy veteran and the preferred candidate of former President Donald Trump. The result was confirmed on Wednesday morning, marking an unexpected upset in the race for a competitive battleground seat.

Mr. Smith, who had not actively campaigned in recent weeks nor filed a campaign finance report beyond a modest $1,850 in fundraising, emerged victorious over Mr. Hassan by roughly a 50 percent to 33 percent margin, with a third candidate, Al Lemmo, receiving around 16 percent of the vote according to returns with more than 95 percent counted.

The district, located in central Michigan, is closely watched as one of the few across the country that supported both a Democratic representative and President Trump in 2024. The seat is currently held by first-term Democrat Kristen McDonald Rivet, and Republicans have targeted it as a prime opportunity to regain ground.

Mr. Smith had officially stepped away from the race in July, endorsing Mr. Lemmo, whose campaign had run ads portraying Mr. Hassan as a “Trojan horse,” highlighting his past Democratic leanings and lack of voting in 2024. Some Lemmo ads also referenced Mr. Hassan’s faith, including images of a woman in a niqab and descriptions of Mr. Hassan as a “proud Muslim,” though Mr. Hassan stated during the campaign that he is a Christian who has studied other faiths. Mr. Lemmo later acknowledged that some campaign ads “didn’t so much appeal to bigotry against Muslims as kind of counted on it,” while expressing personal discomfort given his diverse community.

Mr. Hassan did not respond to interview requests but posted a Facebook video accepting the outcome, expressing hope for future opportunities.

Despite lacking television advertising and a formal campaign infrastructure, Mr. Smith reactivated his bid following his primary victory. He promptly appeared at a GOP event in Macomb County alongside Mike Rogers, the Republican candidate for Senate, signaling party consolidation around his candidacy.

Several high-profile Republicans had backed Mr. Hassan, including Trump, who campaigned for him in Milford last week, as well as House Speaker Mike Johnson and Senator Tim Scott of South Carolina. Speaking on Wednesday, Mr. Trump described Mr. Hassan as a “good person” but suggested his relative obscurity among voters contributed to the loss.

The National Republican Congressional Committee swiftly endorsed Mr. Smith, with spokesman Zach Bannon affirming that the party expected to unseat Ms. McDonald Rivet in November. Meanwhile, the Democratic Congressional Campaign Committee highlighted the unusual outcome as evidence of Republican disarray heading into the general election.

Ms. McDonald Rivet did not respond to requests for comment. The general election contest in this pivotal district remains highly competitive as Republicans rally behind their newly nominated candidate.