Depp, 47, responded after 9-year-old Beatrice Delap sent a letter pleading for help in leading a mutiny against her teachers at Meridian Primary School in Greenwich, a district in southeastern London.
Dressed as his character Captain Jack Sparrow, Depp performed pirate songs and dances for the pupils during the visit with four other cast members on Wednesday.
The actor is currently filming "Pirates of the Caribbean: On Stranger Tides" at the nearby Old Naval College, an opulent 17th-century seafaring center designed by architect Christopher Wren - whose other works include London's St. Paul's Cathedral.
In her letter to Depp, Delap wrote: "We are a bunch of budding young pirates and we're having trouble mutinying against the teachers! We'd love it if you could come and help!"
Teachers said they encourage pupils to write for a real audience in classes. "This just goes to show it can reap great rewards," acting head teacher Jo Graham said.
"The children across the whole school greeted Captain Sparrow with great applause and sang him their own pirate song," the school said in a message on its website. "The event was great fun and the whole school are delighted to see that such creative writing for a real audience and purpose can lead to great things."