Sort by start, then one pass: each interval either reaches the last one out and merges, or starts a new one. Also inserting one interval into a sorted list, and intersecting two lists with one index in each.
This interactive visualization needs JavaScript.