The first lady, dressed in black, and her elder daughter Malia were seen by photographers entering the Gothic-inspired cathedral on the unannounced stop. They were joined by the Obamas' younger daughter Sasha and the first lady's mother Marian Robinson, the official said.
Mrs. Obama made no comment and issued no statement.
Nine people, including the pastor, were killed overnight at a prayer meeting inside a historic black church in downtown Charleston. President Barack Obama said in Washington that he and his wife knew several members of the church, including the slain pastor, Clementa Pinckney.
Earlier Thursday, Mrs. Obama visited the Expo 2015 World's Fair in Milan, which focuses on food and nutrition, where she found kindred spirits in her campaign to promote healthy eating during visits to the U.S. and the Italian pavilions.
Mrs. Obama was greeted by a video image of her husband as she entered the U.S. pavilion, guided by U.S. student delegates to Expo from universities around the United States.
She spent some time discussing the vertical garden covering the length of pavilion, which has rotating panels of herbs and vegetables that are engineered to maximize sunlight exposure.
Mrs. Obama said the pavilion was "awe-inspiring."
"The most impactful part of it, obviously, is the vertical farm, the largest of its kind. And I couldn't help but think about all the issues we face around hunger, around food deserts in our countries and places all over the world. And when you walk around this pavilion, you think the solutions are right in our grasp," Mrs. Obama told some 60 student delegates during a question-and-answer session at the end of the tour.
Mrs. Obama was leading a presidential delegation to Expo, which included the U.S. Ambassador to Italy, John R. Phillips, star chef Mario Batali, NBA all-star Alonzo Mourning and the co-founder of sweetgreen, Nicolas Jammet.
While Mrs. Obama conducted official business, her daughters Malia and Sasha took in some of the rest of the vast Expo, boarding an electric vehicle that ferried them away.
The Expo themes dovetail with the first lady's "Let's Move" initiative to fight childhood obesity through diet and exercise, and she told the student delegates that collective efforts have resulted in a halt to the growth in childhood obesity among America's smallest children.
"We are trying to change the dialogue, create a new norm around food and health, and our culture surrounding food. And we are starting to see some changes," she said.
Earlier, Italian Premier Matteo Renzi's wife, Agnese Landini, took Mrs. Obama around the five-story Italian pavilion. The first ladies stopped to meet with 8-to-10-year-olds from a nearby international elementary school who showed off their video projects, which featured ideas for tackling how to feed 9 billion people by 2050.
One video advised that "food is still good the next day. You just have to make it look different," which got a chuckle from Mrs. Obama.
"It is just so important that all of you are talking about these issues at such a young age," Mrs. Obama told the youngsters. "You are the ones who are going to help change the world."