Barnwell, a 30-year-old lawyer from Woodside, earned almost 63 percent of the ballots, with 1,622 votes compared to Markey's 921 votes, according to results posted on the Board of Elections' website.
The primary victory marks a major upset for Markey, who has represented the 30th Assembly District — which includes Maspeth, Woodside and parts of Long Island City, Astoria, Sunnyside and Middle Village — since 1998.
Barnwell, who previously worked for Councilman Costa Constantinides' office in Astoria, told DNAinfo last week that he threw his hat in the ring because he thinks the district needs a more active representative.
"She's just not getting the job done," he said at the time.
If elected, he said he would focus on tackling corruption and ethics reform in Albany, as well as affordable housing and responding to constituents' quality of life issues.
"I've been giving out my cellphone numbers to voters," he told DNAinfo New York. "You should be able to have a conversation with your representative directly and have something taken care of and addressed."
Barnwell is set to face off against Republican candidate Anthony P. Nunziato in the general election, Board of Elections filings show.