- Disable wifi.
- rm ~/Library/Keychains/login.keychain
- Completely switch off and reboot (NB: choosing "restart" from the apple menu doesn't seem to work).
- Re-activate wifi.
UPDATE: This doesn't actually seem to work all the time. I did finally find a more technical explanation of what exactly is going wrong, as well as another solution (currently working) here.