His visit was seen as another gesture of reconciliation after he quoted a Byzantine emperor who said Islam was violent and irrational earlier in the year.
Istanbul's Grand Mufti Mustafa Cagrici escorted the pope into the mosque, following a tour of Aya Sofya.
The visit was added to Benedict's schedule as a "sign of respect" during his first papal trip to a Muslim nation, the Reverend Federico Lombardi, a Vatican spokesman, said last week.
The Blue Mosque is the best known mosque in
Pope John Paul II, Benedict's predecessor, made the first papal visit to a mosque during a trip to
About 150 nationalists maintained their demonstrations against the pope's visit, saying that the Aya Sofya, which is now a museum, should be re-opened to Muslim worship.
The German-born Pope has already defused much of the tension linked to his visit, his first to a mostly Muslim country, by supporting
When he was a cardinal he spoke out against Turkey joining the EU because of its Muslim roots.
The main thrust of his visit was Christian unity.
In a joint statement, the pope and Ecumenical Patriarch Bartholomew I, the spiritual leader of the world's Christian Orthodox, stressed the need to "preserve Christian roots" in European culture while remaining "open to other religions and their cultural contributions".
They also signed a common declaration that appeared to jointly support Turkish membership if it protected religious liberties.