Book it as a multi-city trip
On the airline's site or any flight search, choose multi-city instead of round trip and enter each flight: home to the stopover city, the stopover city to where you are going, and the way back. On one airline, or an alliance, it is one booking and one ticket.
It often costs little more than flying straight through, and it keeps the whole trip on one booking.
Search engines show the cheapest dates for each flight on its own, not for the trip as a whole, so the order you visit the cities in and the day you move between them can change the total by hundreds. That is the part worth comparing.