DNA compaction is essential to ensure the packaging of the genetic material in living cells and also plays a key role in the epigenetic regulation of gene expression. In both humans and bacteria, DNA packaging is achieved by specific well-conserved proteins. Here, by means of all-atom molecular dynamics simulations, including the determination of relevant free-energy profiles, we rationalize the molecular bases for this remarkable process in bacteria, illustrating the crucial role played by positively charged amino acids of a small histone-like protein. We also present compelling evidence that this histone-like protein alone can induce strong bending of a DNA duplex around its core domain, a process that requires overcoming a major free-energy barrier.