Lina Hidalgo never thought she would work in politics or run for office.
She and her family fled their home country of Colombia as a drug war raged, arriving in the United States in 2005. She studied law, public policy and political science at elite universities as she pursued a career influencing government from the outside.
But on Tuesday, Ms. Hidalgo, a 27-year-old Democrat, narrowly won an upset election to lead Harris County, which includes Houston and is the third-most populous county in the country and the largest in Texas. She beat the 11-year Republican incumbent to become the first woman and the first Latina elected to the county judge office.
Ms. Hidalgo said she decided to run for office after the 2016 election because of the divisiveness it displayed. She ran as an outsider candidate.
“I’m not tied to the powers that be,” she said in an interview on Thursday. “People were inspired. Their hearts led them to speak up in a year in which our democracy seemed to be under threat.”
Tuesday’s midterm elections were unlike any that Texas had seen in decades. Representative Beto O’Rourke lost to Senator Ted Cruz by less than 3 percentage points in a Senate race, one of the smallest margins in years for a Democrat running for statewide office. Democrats also flipped at least two congressional seats, 12 State House seats and two State Senate seats.
[See the full election results in Texas.]
Ms. Hidalgo’s victory showed that the elections also yielded significant changes at local levels, including in the fast-growing, multicultural metropolis of Houston. A record 17 African-American women were elected to judgeships in Harris County, in a campaign they called “Harris County Black Girl Magic.”
One of those women, Latosha Lewis Payne, 44, who was elected to the 55th Civil Court, said she was surprised so many black women were elected. She said the diversity would “increase the fairness and justice in Harris County.”
“The effect of having that many African-American women, but also women in general in the judiciary, is amazing,” Ms. Payne said. “It’s one of those things that you dream it, but you don’t believe that is actually going to happen.”
In her race for county judge, Ms. Hidalgo beat Ed Emmett, who spent eight years in the State Legislature before being appointed as county judge in 2007 after his predecessor resigned. He was elected in 2008 with more than 53 percent of the vote to finish out the term, and re-elected in 2010 and 2014 with about 60 percent and 83 percent of the vote.
On Tuesday, Ms. Hidalgo earned 49.7 percent of the vote and Mr. Emmett 48.2 percent.
Mr. Emmett could not be reached for comment on Thursday. In a series of tweets, he attributed his loss in part to straight-ticket voting, in which voters can select which party they want to vote for and the voting machine automatically selects all candidates of that party. More than 511,000 voters cast straight-ticket Democratic ballots in Harris County, which has a population of more than 4.7 million people, compared with about 408,000 Republican straight-ticket ballots.
“Making up that deficit was just not possible,” Mr. Emmett wrote.
But Ms. Hidalgo said she did not think people voted solely for Democrats “out of reflex.”
“They voted because they knew there were people on the ticket like me,” she said.
Last year, Texas enacted a law eliminating straight-ticket voting starting in 2020, in part because it discourages voters from researching candidates.
Critics had questioned Ms. Hidalgo’s experience, noting that she had never physically attended a meeting of the Harris County Commissioners Court, which she will preside over when she takes office in January. She called it a “nonissue,” saying she had watched live-stream broadcasts of the meetings.
Ms. Hidalgo said she ran a targeted campaign with television advertisements and door-to-door outreach.
“This didn’t happen by accident,” she said during her victory speech on Tuesday. “We’ve been working on this for 15 months.”
Michael O. Adams, the chairman of the political science department at Texas Southern University in Houston, pointed to Mr. O’Rourke’s candidacy, a backlash to President Trump and a diversifying populace in Harris County and its suburbs as helping Democrats in the Houston area.
He said that without the straight-ticket ballots, he would not have expected Ms. Hidalgo or some other local Democratic candidates to win their elections. He said Mr. Emmett was a centrist politician with cross-party appeal.
“I know Harris County has been moving or trending toward being blue,” Dr. Adams said. “I think what happened on the ground here is a tremendous get-out-the-vote effort.”
For Ms. Hidalgo, arriving in the United States in 2005 and going to a public high school presented a contrast with the corruption and violence she had seen in Colombia.
“You couldn’t go to the grocery store without worrying about a bomb,” she said. “Everyone knew somebody who had been kidnapped.”
She attended Stanford University, graduating with a degree in political science in 2013, the same year she became a United States citizen.
After that, she worked for a nonprofit promoting press freedom internationally and as a Spanish-language interpreter at the Texas Medical Center in Houston.
In 2015, Ms. Hidalgo began pursuing a joint degree in public policy and law at the Kennedy School at Harvard University and New York University.
After she decided to run for office, she put her degree on hold. During the campaign, she drew on her immigrant background and focused on criminal justice reform, transparency in county government and flooding control after Hurricane Harvey and other severe storms ravaged Houston.
She said of her victory, “I really hope that folks remember this year as the year in which people saw and stepped up and volunteered for the first time and got involved in campaigns for the first time.”