Here's another solution that is all in the software (no diodes or gates!). I'm not sure if it would be wise though.
I will use 4 pins (pins 8 through 11, but 1 to 4 for this discussion). All will be configured as inputs initially.
Pin 1 will monitor a button press. Upon button press, Pin 2 will be configured to be an output and then will be set HIGH to activate the relay. After an amount of time specified in software, the pin will be set to LOW and configured back to an input.
Meanwhile, Pin 3 will monitor the external signal. As soon as an external 5V signal is detected, Pin 4 will be configured to be an output, and will be set HIGH to activate the relay. As soon as Pin 3 detects that the 5V signal has ceased, Pin 4 will be set LOW and configured back to an input.
In doing this, Pins 2 and 4 that are connected to each other will never be in danger of both being an output while one is HIGH and one is LOW at the same time.
The only problem that I see that this might have is if both inputs were HIGH, then one went LOW... There would be a miniscule amount of time between when the output pin went LOW and when it is configured to an input, and I don't know if that small amount of time is enough to fry the pins. Fortunately, when one output is HIGH, the software will be stuck in a while loop associated with that pin, which means pins 2 and 4 will never both get HIGH together. (In other words, there will never be a time when both are configured as outputs, so everything is fine.)