While I was making a morning coffee at work, some sugar from the spoon started to fly away, seemingly towards some foam cups. Can this be explained by magnetism?
Electro-magnetism is a good guess, simply because it's the only force you commonly see that's powerful enough. It's not very useful as an explanation, though, because almost everything you see around you is due to electro-magnetism (e.g. the way the spoon holds together in the first place, or the light that allows you to see the sugar, or the way the water "sticks" to having a fluid surface, or the way the individual atoms of the sugar stick together...). The real question is "What kind of EM is responsible?"
It's not ferro-magnetism (the kind you see with old-school fridge magnets) - neither the foam nor the sugar are ferro-magnetic. It's not para-magnetism either.
It's not due to molecular nor atomic bonds (the kind that holds molecules together, or the residual force that causes e.g. hydrogen bridges) - the distance involved is too large.
It's not dia-magnetism (remember those frog levitation videos?). That would require massive magnetic fields.
I could go on, but there's plenty of other cases that obviously don't apply, so let's skip to the end:
The interesting point is that plastics are usually electric isolants. This is very important, because it means that when they acquire a charge imbalance, it's not equalised very quickly - the current can't flow readily. This means that it's possible for one side to have a slight positive charge, while the other side has a slight negative charge (in a metal, in contrast, the charges would "mix" to maintain an overall neutral charge).
This leads to another common sight of electromagnetism in the common household – static electricity. And this is most likely what's happening here - the cup is statically charged, which causes attraction between the slightly charged cup, and the sugar which is also slightly charged in turn (if we assume the cup is slightly positively charged, it will attract negative charges in the sugar, causing a slight charge imbalance in the sugar as well - and now you have slightly positive + slightly negative, resulting in a net attraction).
Finally, to answer your title question, Can sugar be affected by a magnetic field?
Yes. Sugar is made out of parts which interact using the electro-magnetic force, and thus it can be affected by a magnetic field. In the end, it's that simple. Even if it was even a tiny residual force (1 proton + 1 electron aren't exactly "zero" charge), it would allow interaction. So if you want to be exact, only the objects that don't interact in EM at all can be non-affected by a magnetic field - for example, neutral neutrinos, or the (more or less) hypothetical dark energy and dark matter (the thinking is that they're dark precisely because they don't interact with EM - this includes visible light as well as magnetism).
Not magnetism but static electricity - the other side of the electromagnetic force. Sorry this answer is short, but I think the link will give you all the information you need.