The flags had been raised in front of the China Pavilion on May 1, and flew over the 5.28-square-kilometer Expo site for the past 184 days.
More than 73 million visitors were treated to a feast of cultures and technologies focused on the theme "Better City, Better Life" in the biggest Expo since the world event began with the Great Exhibition of 1851 in London.
A crowd of around 8,000, joined by singers and dancers on stage at the Culture Center, erupted into applause when Chinese Premier Wen Jiabao declared the Expo formally closed last night.
Wen said the Shanghai Expo had been a splendid event and added a glorious chapter to Expo history.
Calling the event "eye-opening" and "unforgettable." the premier expressed gratitude on behalf of the Chinese government and paid tribute to all the people who had participated in, supported and contributed to the first Expo held by a developing country.
Chinese Vice Premier Wang Qishan said the Expo has made China and the world come closer together, and that a more open, inclusive and culturally advanced China that steadily moves forward will join other countries to usher in an ever brighter future for all.
He said the Expo spirit will be carried forward from generation to generation.
"I am convinced that the vision of 'Better City, Better Life' will become reality," Wang said.
Jean-Pierre Lafon, president of World Expo supervising body the International Exhibitions Bureau (BIE), said the Shanghai World Expo was an "astounding success."
Speaking in Chinese, Lafon said: "Expo 2010 is the success of China. It is the success of Shanghai ... It is also the great success of the World Expo."
The BIE flag was lowered and handed over by Shanghai Mayor Han Zheng and Hong Hao, director general of the Bureau of Shanghai World Expo Coordination to Letizia Moratti, mayor of Milan, and Giuseppe Sala, CEO of the Milan Expo 2015.
China's top entertainers and athletes, including Shanghai's 110m-hurdler Liu Xiang, film star Jackie Chan and pop singer Andy Lau, also helped mark the end of Expo.
The Shanghai World Expo attracted 246 nations and international organizations, the largest-ever number at a World Expo. More than 73 million people visited the site - a record in Expo history.
The Expo also set a record for the largest daily attendance, when more than 1.03 million visitors flocked to the site on October 16.
These figures broke records set at the Osaka World Expo in 1970, which recorded 64.22 million visitors, including 844,000 on a single day.