Franny Armstrong called for help as she was surrounded and pushed by the girls, one of whom had an iron bar, in Camden, north London, on Monday night.
The mayor, who was cycling past, stopped and chased the girls down the street, calling them: "Oiks".
Ms Armstrong said: "He was my knight on a shining bicycle."
Film-maker and climate change activist Ms Armstrong was walking home when she was approached by the group of hoodie-wearing girls.
She said: "I was texting on my phone so didn't notice the girls until they pushed me against the car, quite hard.
"I noticed that one had an iron bar in her hand - it was very frightening."
Ms Armstrong called out for help from the nearest cyclist, who turned out to be Mr Johnson.
"He said to the girls: 'What do you think you are doing?'
"He picked up the iron bar, called after the girls and cycled after them."
She said the mayor returned a few minutes later and walked her home.
Ms Armstrong directed the film Age of Stupid and is the founder of the 10:10 campaign, which aims to cut carbon emissions by 10% in 2010.
She admitted that she did not agree with Mr Johnson's politics and had voted for rival Ken Livingstone in the 2008 mayoral election.
But Ms Armstrong added: "If you find yourself down a dark alleyway and in trouble I think Boris would be of more use than Ken."
A spokeswoman for Mr Johnson confirmed that the incident took place but said the mayor would not comment further on the matter.
I know a lot of people hate the dude, but I liked it last year when he said the London snowstorms were "no excuse for a mass skive." Also he was my sole VIP sighting in London.