Cargo planes secure their load meticulously and if it breaks loose, the result is sometimes catastrophic. However, how do you prevent fuel sloshing inside the tanks and causing the same problems as loose cargo?
The answer is no, but some shifting of the center of gravity (c.g.) due to attitude is unavoidable.
Tanks are subdivided so the c.g. shift within a single tank is small. You can notice the sloshing after a landing when the aircraft has come to a complete stop after taxiing: It will gently rock back and forth due to the sloshing in the tanks.
Some fighter aircraft use a sponge-like mesh in their tanks which is very effective in breaking up sloshing. It takes up approx. 2% of internal volume. However, in a nose-up attitude the fuel will still collect at the back of the tanks, and again only distributing fuel over several tanks will prevent a significant c.g. shift.
Subdividing also helps in spanwise direction to prevent high loads on wing ribs when the aircraft rolls. Remember, an F-16 has a top roll rate of 720°/s, which creates a significant inertial pressure on the wing's tank walls.
There are dividers (baffles) in the fuel tank precisely to stop the sloshing. They are just large plates that will stop the fuel from flowing across.
High maneuver jets will use bladder tanks (so no air is in the tank with the fuel) as a way to contain the fuel.
It would theoretically be possible for sloshing fuel to shift the center of gravity (CG) enough to cause an uncontrollable pitch up, leading to a stall. Designers know this and use various methods to prevent fuel from shifting too much when maneuvering.
First of all, the fuel is generally stored close to the CG (at least longitudinally, which is in pitch), mostly in the wings and sometimes in the fuselage between the wings. This is to prevent large changes in the CG as fuel is consumed during the flight. So while fuel certainly is heavy, movement will be close to the CG and affect balance less.
As Peter Kämpf notes, roll conditions are important as well, and of course having fuel out in the wings will affect latitudinal stability (but also longitudinal with increasing wing sweep). One way to control this is through the use of baffles (or subdivisions). These limit the amount of area available for the liquid to move between areas, preventing large changes during maneuvers but allowing enough fuel to flow during regular fuel burn, refueling, or tank tranfers. Baffles have the added benefit of providing more structural strength, which is particularly important in aircraft. Wing ribs act as baffles in the wings.