Interesting that they only stay on with the engine running but short out otherwise. Check the wiring where it enters or leaves the bow or stern railings to see if it has rubbed through and shorting out where the positive could touch a grounded part.
I would go with Dan's suggestion first - I had a similar issue and after fault finding to the point of having to physically cut the cable of each light - re-wire and then cut the next one I found out it was a faulty starboard nav light causing the problem.
I had no wire failure that could be spotted and as these were sealed units it was the only way I could do it - plus I was underway in the middle of the night when it happened!
I believe although not 100% sure that some water had got into the 'sealed' light and was causing it to short (or it had just developed a fault after 12 years...) - although its not an ideal practice, I did find it after about 5 minutes of cutting, re-crimping, cutting, re-crimping. Once it was removed from the circuit there was no tripping and since replacing it I've never had a problem.