Yes you can, I have seen it done. The real world risk of a fire or explosion is pretty limited, modern cars don’t give off a lot of sparks. One issue may be that if you have an electric gas door release, there’s a chance it won’t open when the engine is running, if that’s how the car is programmed.
10 minutes of running the engine will probably charge the battery enough to start the car again, so unless the tank is really dry this might be less of a problem than you think.
It might be a bit dangerous, depending on how far the battery can move. On many cars, there’s a other things in the way that will stop it from getting very far. However, it isn’t good for the battery to be rattling around, and if it pulls on the battery cables and that causes connection issues all sorts of weird stuff will start to happen, possibly at a very inconvenient time.