The 1/r^2 law results from what are called monopoles, which are basically point-sources of the field. Single electric charges are monopoles which is why the field of a single electric source goes like 1/r^2 as you move away from it. If you put a positive and negative charge near each other (and keep them separated), you have what's called a dipole. Since there's one positive and one negative charge, there's a 1/r^2 field pointing in towards the charges and a 1/r^2 field pointing away from the charges. The 1/r^2 terms cancel each other out and you end up with the next biggest term, which is 1/r^3. This is called an electric dipole field. You can have quadrupoles, octopoles, etc., each one constructed by canceling out the previous -pole which leads to a faster decay in powers of 1/r.
Magnets are a little trickier since no one has ever seen a magnetic monopole. However, particle theorists like the idea of magnetic monopoles, since a lot of their theories predict them (I don't know the details of why). If they exist, they would decay like 1/r^2, but since no one has ever seen them, most of our magnets will be dipoles, which decay like 1/r^3. You could of course design a magnetic quadrupole or octopole.
You can, of course, design a magnetic field that behaves differently from this over a region of space. For example, if you're near a long current carrying wire, the field goes like 1/r multiplied by the current carried in the wire (with some other constants as well), but as you get far away from it, things have to start behaving like dipoles.