Hey there eemuska,
Thanks for reaching out to the Apple Support Communities. For the best steps that can help with troubleshooting the specific error you're seeing, check out the steps listed in the following resource that can help: If you see error 9, 4005, 4013, or 4014 when you restore your iPhone, iPad, or iPod touch - Apple Support
1. Make sure that your Mac has the latest version of macOS or the latest version of iTunes.
2. Force your device to restart:
- iPad models without a Home button: Press and quickly release the volume button closest to the top button. Press and quickly release the volume button farthest from the top button. Press and hold the top button until the device restarts. If you're not sure, see which buttons you need to press to restart your iPad.
- iPhone 8 or later: Press and quickly release the volume up button. Press and quickly release the volume down button. Press and hold the side button until you see the Apple logo.
- iPhone 7, iPhone 7 Plus, and iPod touch (7th generation): Press and hold both the side (or top) button and the volume down button until you see the Apple logo.
- iPad models with a Home button, iPhone 6s or earlier, and iPod touch (6th generation) or earlier: Press and hold both the side (or top) button and the Home button until you see the Apple logo.
3. Connect your device to your computer using a USB cable. Locate your device on your computer.
4. When you see the option to update or restore, click Update — not Restore — to reinstall the software and keep your personal data.
If you still need help, try these steps
If you can update your device but it starts up in recovery mode, follow the steps above again. On step 4, choose Restore instead of Update. After the restore completes, you need to set up your device from a backup.
If you still see an error during the update:
1. Check for updates to your Mac or PC. If you restart your computer for an update, check for updates again after you restart.
2. Try to restore your device using another USB cable.
3. Try to restore your device on another computer.
For some additional steps that can help with troubleshooting the issue further, take a look at this additional link here: If you see an error when you update or restore your iPhone, iPad, or iPod - Apple Support
Lastly, you mentioned that the iPhone would exit recovery mode when trying to restore the device. We do want to let you know that this would be expected, and if the download takes more than 15 minutes and the iPhone exits recovery mode, wait for the download to finish then put the iPhone into recovery mode again.
Keep us updated on the results.
Take care!