As atoms get too close to one another their charges begin to repel each other. Once they’re close enough that they can “see” the other atom, the electrons on the near side of both atoms begin to repel each other and move more to the far side of both atoms. This leaves the positively charged nuclei facing each other.
Electrons swarm around the nuclei of their atoms (in this case Helium 4). When they're brought very close together the electron clouds shift and the atoms briefly polarize in such a way that they repel.
Basically, when two atoms come too close they behave exactly like magnets brought together with the “north” ends pointing together.
(Everything up to here has been wrong. )
This certainly isn’t the whole story. Quantum chemistry isn’t rocket science, but it’s still pretty complicated. Atoms can share electrons, or their electrons can move so that they behave like attracting magnets, and a whole mess of other things. For example, attractive van der Waal forces can show up when atoms are close, but not too close. Slight fluctuations in the arrangement of electrons in one atom induces a sympathetic arrangement in nearby atoms (this is more specifically a “London dispersion force “). As a result, the atoms end up with dipoles lined up in a “+- +-” way, instead of a “-+ +-” way, like in
the picture above.
In general, the force is extremely small. But it is just strong enough to hold liquid helium to itself (otherwise it would be a gas), and hold geckos to walls.
Geckos have weird feet because they have evolved to optimize the chance of random dipole interactions between the atoms in their feet and the atoms of whatever they're climbing. As a result, they can climb vetically on materials as smooth as glass. Pictured here is a gecko excited to learn that someone remembered his birthday.
Addressing the fact that matter is mostly empty space, if you really squeeze matter you’ll find that the electrical forces can no longer hold atoms apart. Basically, they find that it’s easier for the electrons and protons to fuse together and form neutrons. Once all the charges are out of the way the atoms (now balls of neutrons) are free to collapse together. At that point the only thing holding them apart is “Pauli pressure”, which is fancy quantum physics speak for “they can’t be in the same place”.
The only time this happens in nature is in neutron stars. To get an idea for what happens when you “deflate” matter: If you were to crush a 50m Olympic size swimming pool into neutron star material, it would be about 0.05mm long, which is about the width of a single hair.