He was speaking to Muslims who had sought shelter in the capital Bangui after nearly three years of violence between Christians and Muslims.
The mosque visit was seen as perhaps the most difficult part of his Africa tour, a BBC correspondent says
Pope Francis then held the final Mass of his Africa trip in Bangui.
More than 100,000 Muslims left the capital as a result of the fighting but 15,000 are left in an area called PK5, according to the campaign group Human Rights Watch.
Imam Tidiani Moussa Naibi thanked the Pope for his visit and said it was “a symbol which we all understand”, the AP news agency reports.
On Sunday, the Pope called on fighting factions in the CAR to lay down their weapons.
About half of CAR’s population is Christian and 15% are Muslim.
Celebrating Mass in Bangui, he said they should instead arm themselves “with justice, love, mercy and authentic peace”.
Earlier, he said he hoped next month’s election in the CAR would open a “new chapter” for the country.
The trip to the CAR is the pontiff’s first visit to a conflict zone and the final stop on his three-nation African tour that also took in Kenya and Uganda.
Conflict has blighted the CAR for decades but it was only in 2013 that the fighting took on a religious form.
President Francois Bozize was ousted in a coup in March 2013 and a group of mostly Muslim rebels from the north, the Seleka, marched on Bangui, briefly taking control of the country.
Their rebellion tapped into a feeling northerners had of being excluded and unrepresented by the central government, correspondents say.
They targeted churches and Christian communities, which triggered the creation of the anti-Balaka – meaning anti-violence – militias, and led to a downward spiral of tit-for-tat violence which continues.
Towns and villages are divided, with hundreds of thousands of people displaced into camps divided along religious lines.