For some reason it now works. I flashed the latest TWRP by codeworkx from the TWRP I had installed, and now it works.
I cannot explain this, because I have tried all these things before, with no luck (including reinstalling different versions of TWRP, rebooting, etc.).