The second-largest city in Maine, home to thousands of African newcomers, has elected a Somali American to its city council following a campaign that was marred by racist attacks and threats fueled by social media.

Safiya Khalid, 23, soundly defeated a fellow Democrat on Tuesday for a seat on the Lewiston City Council.

Shrugging off attacks on her skin color and faith, Ms. Khalid declared that "community organizers beat internet trolls."

The attacks didn't seem to faze voters. Ms. Khalid won with nearly 70% of the vote to make history in the former mill city.

"I worked really hard. I knocked on thousands of doors. That's what paid off," Ms. Khalid told The Associated Press in an interview Wednesday.

Maine is the nation's whitest state, but it is home to a growing population of Africans who have fled their homeland.

First- and second-generation candidates from four African countries – Somalia, Congo, Ghana, and Nigeria – won seats on city councils and school committees across the state, continuing an established trend, said Mufalo Chitam, executive director of the Maine Immigrants' Rights Coalition.

"There's been a push for us to have bigger representation in office in the towns," she said. "That's where the decisions are made. If we're not in those offices, then someone is going to make the decisions for us."

In Lewiston, ugly hateful messages, mostly from out of state, targeted Ms. Khalid. Someone said she should be stoned. Another shared her home address on a Facebook group. Some of the attacks drove her to tears.

Opponents spread a photo of her when she was a 15-year-old high school freshman flipping off the camera. The photo was taken by a friend.

"I was a child," she said. "I was 15. I didn't know any better."

Ms. Khalid deleted the Facebook app from her cellphone and deactivated her Twitter account. Then she focused on continuing to knock on doors in her ward whenever she wasn't at her job as a caseworker.

Mainers generally don't like outsiders meddling in their affairs, so the out-of-state social media trolling could have backfired to a certain extent, Lewiston voter Amber St. Onge said.

"A teenager pointing a middle finger is not a big scandal," added Abdifatah Afrah, of Lewiston. "That's nothing compared to what we see in the news with politicians every day."

Somalis began moving to Lewiston two decades ago in search of affordable housing after many settled in Portland, 36 miles away. The city of 36,000, second in population in Maine only to Portland, is now home to more than 5,000 Africans.

Ms. Khalid was born in Somalia and remembers living in a refugee camp before coming to the United States.

As a city councilor, she wants to ensure that there is affordable housing that is free from lead contamination, which is a problem in the city's older housing stock. She wants to boost aging infrastructure, bring in investment, and support local businesses. She also wants to boost schools.

"When I came here, I didn't know how to write my name or speak any word of English. I am who I am because of public education. Our children deserve the highest-quality education," she said.

Lewiston Mayor Kristen Cloutier said she was impressed by the poise showed by the young politician to ensure people in her community are represented and have a seat at the table.

Ms. Khalid will be the youngest person on the council in January.

Get the Monitor Stories you care about delivered to your inbox. By signing up, you agree to our Privacy Policy

"If those [messages] had been directed at me, I would've been hiding under my bed," Ms. Cloutier said. "I don't know that I would've had the courage to fight another day. That speaks to her resiliency and her dedication."

This story was reported by The Associated Press.