Your cat may have a problem called Feline Lower Urinary Tract Disease (FLUTD) It happens when crystals are formed in the bladder which block the urethra. Male cats are affected more commonly than females, as they have a longer urethra. Basically, the crystals sit inside the urethra, and stop the cat from unrinating. The bladder fills up and distents, causing pain and distress. The cat feels like he needs to go to the toilet desperarely, and keeps on trying, but is unable to pass enough urine to alleviate the problem. The dangers are many - urine can wash backwards towards the kidneys causing infection and kidney failure. There is also the rare problem of rupture of the bladder. In any case, the cat is usually very distressed, and in considerable pain (Imagine how you would feel if you were busting to wee but couldn't)
The only cure for FLUTD is veterinary treatment. Get him assessed as soon as you can to see if this is the problem.
Possible urinary blockage. If that is what it is, it can be life threatening very fast. Can you feel a full bladder? You might call a nighttime vet and describe what's going on and see if they think it can wait until morning to see your regular vet.