One way to do this is to use a separate UI camera.
1. In the Hierarchy, right-click on MainCamera, and select Camera. This will add a new child camera. I named it UICamera and configured it like this:

(For 3D scenes, you don't set Projection to Orthographic.)
2. Then inspect the MainCamera, click the Culling Mask dropdown, and deselect UI:

The MainCamera, which has a Depth of -1, will first draw everything except objects on the UI layer. Then the UICamera, which has a Depth of 0, will draw only objects that are on the UI layer. (Any depth numbers are fine, as long as the UICamera's depth is higher.)
3. Set your UI's layer to UI.