Yes, a battery can fail while engine is running, but there are a lot of more likely causes for the engine to die.
There are a lot of members on this sight that have more knowledge than me, but:
Can you tell us: Will the starter turn the engine now (attempt to start)? Will the lights burn? If not: a battery cable could have come loose or been damaged (or the battery could have failed). If you still have lights or if the starter turns the engine then something else is wrong and we will need to suggest other options.