Christoffer Dulny had anonymously written posts on various Swedish websites, revealed the Expressen newspaper on Monday.
"Foreigners are the absolute worst when it comes to lying and manipulating (…) they're absolutely shameless," he wrote.
After he was confronted by the paper, Dulny stepped down on Tuesday, saying in a statement that the move was "in the party's best interests".
He told Sveriges Radio that the decision was "100 percent his own choice".
The party's press officer added that racist opinions could be found among individual politicians in other parties too, and questioned Expressen's timing in releasing the revelations so close to the national elections, which take place on Sunday.
Last week, another Sweden Democrat left her post after pictures surfaced of her wearing a Nazi swastika armband while apparently cleaning her house.