If you're attacked, you can only fight to the end (in the future I might add an ability to flee or something). However, one way to avoid enemies to stop exploring the level once you believe there is nothing important left and know the way to the next one.