The attack happened when five militants took hostages at Holey Artisan Bakery in an affluent area of the capital, Dhaka.
The stand-off between hostage takers and police lasted almost 12 hours. Twenty-eight people died in the attack, including nine Italians.
The Pope embraced and comforted 36 members of the families of the Italian victims.
"It's easy to take the road from love that leads to hatred, while it is difficult to do the opposite: from bitterness and hatred to go towards love," he said.
"You are left in anger, bitterness and desire for revenge, but you have embarked, with the pain inside, on the path of love to build and help the people of Bangladesh, especially young people so that they can study: this is to sow peace and I thank you, for me it is an example."
The families presented the pontiff with nine olive tree saplings to honour their loved ones.
The Pope is expected to visit Bangladesh in 2017, although no date has been announced.