I do not believe that humour is a counter to tragedy although it is true that many people who suffer some tragedy have a reaction similar to that of experiencing something humourous.
Humour is largely a product of the inadequacy of language and by that I mean both the thought process as well as the verbalisation. For example, "Three men walk into a bar.... OUCH!!!" is funny because the word "bar" has two meanings and so when people automatically assume its meaning to be "pub" the subsequent failure of the joke to live up to their expectations provokes humour. Additionally, the fact that many jokes start with some variation of "Three men walk into a bar..." whilst using the word "bar" to mean "pub" enhances this effect.
This method of explaining humour is especially important because it allows us to explain why something which was initially funny, loses its humour. This is because once we have heard the joke, our mind remembers the play on words so that next time we are told it subconciously our mind is thinking about the second meaning (even if it is long enough afterwards for our concious mind to have forgotten the joke) and so the expectation that the joke requires in order to be funny, fails to materialise in our mind. Similarly, the joke is far less funny when written down because when we read something that is familiar, our tendancy is to skip ahead meaning that we have read the punchline before we have had a chance to bring up the expectation. The same line of reasoning can be used to show why analysing a joke and explaining a joke equally lead to little humour.
Now what has this got to do with tragedy? Well essentially, when we are first confronted with tragedy, our brain is faced with the task of coping with reality. It is quite common to hear of people who have suffered a serious tragedy to break into fits of laughter and the reason for this is fairly similar to why we initially found a joke funny. The brain, when faced with something with a massive negative emotional interest, is quite likely to try and deny the reality of the situation either through repression or denial. However, it does not do this completely (most of the time) since we are still recieving sense information.
We now have a situation where the information we are getting from the outside world via our senses is being interpreted incorrectly by our brain which is similar to misunderstanding of the usage of the term "bar". The fact that the brain cannot block off reality completely (although it does sometimes such as when a person faints from shock) gives us the knowledge that our assumption is wrong which is similar to the punchline. This is almost identical to the reason why a person laughs when they are relieved about something.