Using a comma before a subordinate clause

Solution 1:

If you take a look at this webpage about main and subordinate clauses, you can easily see how the comma in your second example turns the first part of the sentence into the subordinate clause rather than the last part.

In your example:

The President was opening a new university, when a bomb went off.

The fact that a bomb went off is your main point of discussion. The fact that the President was opening a new university is incidental.

In your first example you are talking about the incident as a whole (where did the bomb go off?).

Solution 2:

Consider this...

The person was eating a sandwich when a phone rang.

This sentence indicates to the reader what the person was doing and something that happened at that moment.

Subject 1: the person

Subject 2: the phone

The person was eating a sandwich, when a phone rang.

This sentence indicates to the reader that these are two separate events happening to the subject.

Subject 1: the person.