On David Bowie's official website. There's a section where David responds to members' questions. Somebody asked him about the writing of Under Pressure, and I thought it would interest the folks over here:
A: The song was written from the ground up on the night I visited their studio. I believe the riff had already been written by Freddie and the others so then we jointly put together the different chord sections to make it a cohesive piece of music. Then Freddie and I came up with our individual top line melodies. So when you hear Freddie sing, that's what he wrote and when you hear me sing, that was mine. Then we worked on the lyrics together. I still cannot believe that we had the whole thing written and recorded in one evening flat. Quite a feat for what is actually a fairly complicated song.
Source: Posted by Mr. Bad Guy in the notice board.