One could make the slugs from ice, or something else that will sublimate with time. Doesn't help with hitting a different space target, but if it gets too close to a star or planet it will melt/burn up. If you need to use it in a railgun, a ferrous discarding sabot of some kind could be used to propel the round and fall away after leaving the barrel. This means debris is created, but not immediately dangerous to folks downrange.
Edit: if the sabot is spring loaded to separate from the main slug, a nearby EM field can capture the debris.
Edit2: Build the sabot capture magnet into the last part of the barrel, so it is pulled directly away/back from the slug.