The Saturday evening attack took place in an apartment building hallway and was the latest incident targeting foreigners or minorities in Russia's second-largest city.
Aliu Tunkara, who heads a civic group for Africans in St Petersburg, said the girl was returning home after a walk and had just entered the building when two men stabbed her.
Alexander Klaus, an investigator with the city prosecutor's office, said in televised comments that during the attack nothing was stolen from the girl, whose father is from Mali and whose mother is Russian.
He said the girl had been hospitalised in satisfactory condition.
"The attack has caused a strong public reaction and is being investigated under charges of hooliganism and attempted murder," city prosecutor Sergei Zaitsev said in televised comments.
"We are considering xenophobia as a motive."
The incident came just days after a St Petersburg jury acquitted a teenager of fatally stabbing a 9-year-old Tajik girl two years ago.
That killing drew wide public attention, provoking protests from Tajikistan and underscoring an increase in hate crimes in Russia's major cities.
Tunkara said he thought Saturday's attack was connected to the jury decision.
"Since nobody was punished for the murder of the girl, people with similar nationalist attitudes could now feel that they have nothing to fear in committing such actions," he said.
Rights groups argue Russian authorities do little or nothing to combat racial crimes.