When 23-year-old Safiya Khalid was elected to the city council of Lewiston, Maine, last week she nabbed a collection of “firsts” – youngest person ever elected to the council, and its first Somali-American – but the race for her had always been about making sure everyone in the city felt the sense of community her family experienced when they moved there from war-torn Somalia.

“What I received here in Lewiston, my family and I in 2006, I want to open that to all people in Lewiston and to encourage young people to live and work in Lewiston and that means building a vibrant community for all of us,” Khalid told the Guardian.

Khalid was one of dozens to secure a historical election seat in local and statewide elections on Tuesday. Boston diversified its city council, Kentucky elected its first black attorney general, Virginia elected its first Muslim state senator, and in Tucson, Arizona, the city elected its first Latina mayor.

This deepening crack in the old traditions of political power arrived four months after Donald Trump told four female members of Congress to go back to their country – including Ilhan Omar, a former refugee from Somalia like Khalid.

Khalid has vivid memories of her first few weeks in the United States, when she lived in an apartment with her brother and mother in New Jersey. Struggling to overcome the language barrier, Khalid’s mother started to stand outside each day saying, “As-salamu alaykum” (peace be upon you) to each person who walked by, hoping to connect with somebody in this brand new country.

Khalid, then seven years old, would watch from the window every day with her two-year-old brother, as their mother was ignored and pushed out of the way until a young man responded appropriately: “Wa alaykumu s-salam” (peace be upon you too). Her mother dissolved into tears and hugs in the stranger’s arms.

“It was the most beautiful sight you’d ever seen,” Khalid said.

The young man did not actually speak Somali, but they were able to manage some communication because he spoke Arabic, and the next day, he brought a Somali family over to give them a short tutorial in American life.

Khalid’s mother resisted the family’s offers to get them set up in New York City and insisted on moving somewhere more close-knit. They suggested Lewiston, Maine, and the next day, the family took a bus to the northern city. Khalid said her family “found what we were looking for” in the city of 36,000.

Nadia Mohamed won a seat on the city council in St Louis Park, Minnesota. ‘I have pretty much knocked on every door in the city.’ Photograph: Supplied

Seeking a city council seat there 13 years later, Khalid campaigned on a platform of affordable housing, supporting small business, encouraging investments to the city, addressing lead contamination issues in old homes and expanding resources for the education system.

After receiving training through Emerge Maine, which helps Democratic women who want to run for office, Khalid embarked on an intense door-knocking campaign that she estimates brought her to the homes of more 1,000 people from March to election day.

“I’m young and I don’t know everything, to be honest, and I want to have the input of the community and have them be stakeholders in the process,” Khalid said.

The most negative reactions she received were a polite “no thank you,” but an ugly campaign to discredit her emerged on social media in the weeks before the election.

People from the other side of the country were messaging her on Facebook with violent threats and racist comments, prompting her to shut down her page to focus on the election.

Now that she’s won, the troll campaign has blurred as accolades pour in from political giants. Julián Castro tweeted Khalid was “an inspiration” and Hillary Clinton shared her photo and story online. “It’s mindblowing,” Khalid said, adding that she would have to start using Twitter more because she didn’t use it much before.

.@Safiya_S_Khalid arrived in Lewiston, Maine as a refugee 10 years ago.



This week, she became the first Somali-American to be elected to Lewiston’s city council.



Hers is just one of @OnwardTogether partner @RunforSomething's 72 election night wins: https://t.co/3iyzqui7mB pic.twitter.com/fIaOxZDduK — Hillary Clinton (@HillaryClinton) November 7, 2019

Nadia Mohamed, who like Khalid is 23 and a former refugee from Somalia, was also recovering from the onslaught of international attention she received after winning a seat on the city council in St Louis Park, Minnesota.

Mohamed asked her brother to see what people were saying online this week – which included a conspiracy that she doesn’t speak English (she does, perfectly) – but avoided examining the social media reaction herself. “It’s not worth my time,” Mohamed said, reveling instead in how great it felt to have won the election.

After living in countries where the majority of people were black until she was 10, it took some time for Mohamed to get used to being somewhere where her race, ethnicity and Muslim faith put her into boxes she hadn’t realized existed before.

“It didn’t sit well with me that I felt like a visitor, so I started doing community engagement,” Mohamed said.

For the past three years, she has been working on the St Louis Park police department’s Multicultural Advisory Committee (Mac) to improve relations between different communities in the city.

It was through this community-building work that she met Thom Miller, whose seat she is taking on the city council. Mohamed said Miller asked her for help to find a more diverse candidate to take his seat on the all-white city council. Mohamed spent two weeks thinking about people who could be a good fit until it clicked: she could run.

“I went back with 1,001 questions,” Mohamed said. “I’m like: ‘Listen, I’m thinking of running, but am I too young? I am still in school – is that going to get in the middle of my education? What’s going to happen?’”

She said Miller told her to relax and focus on the community.

With the same energy and enthusiasm she used while hosting Iftar dinners to help community members better understand Islam, Mohamed began knocking on doors, asking people what they wanted from their city council.

“It really gave me a sense of home,” Mohamed said. “I have pretty much knocked on every door in the city.”