I was testing on the enwiki sandbox; I tried it again and looked at the source, I got:
<p><a href="/wiki/Foo" title="Foo"></a></p> <pre>Magic link! </pre>
Somewhere along the line, something is closing the anchor before the pre block.
Something has changed since I last updated my local copy (a couple of weeks ago, or so), then, or enwiki has a different config to me.