OK, thanks for the extra information.
I think there are a few possibilities here that should be pursued.
First and foremost I think you will need to see a vet asap. No matter what the primary cause, this could turn into a real problem if his rear is too sore to comfortably pass stool.
I think this could be an infected anal sac. There are 2 anal sacs located near the rectum that exit out through little ducts in the anal sphincter. They can become impacted, infected, abscessed and be quite painful. This will require a vet to empty and +/- flush and cleanse the area. Antibiotics and anti-inflammatory medication are necessary for effective treatment.
This could also be swelling and enlargement of the perianal area due to male sex hormones. Your dog is the right age to have some enlargement in this area and sometimes it gets extreme and can cause problems with passing stool. In this case, and in case the prostate is also enlarged and that is causing him pain on passing stool, neutering is the treatment that will cure it.
There are also miscellaneous more superficial perianal infections and even tumors and growths that can cause these symptoms you are seeing.
You really should plan to take him to the vet tomorrow. If he will allow it tonight, you could use a warm, moist compress to the area and then apply some neosporin to any red areas. If he is painful you can give him a buffered aspirin (NO tylenol or ibuprofen!!) tonight to ease the pain.
I hope this answers your question. If not, I'll be happy to follow up with you.