The Drava InterCity train route between Budapest and Sarajevo is pretty quick and comfortable, although this direct service operates only once per day in either direction. First class seating and a buffet car is available between Budapest and Pecs.
The journey is relatively long and prone to delays. We recommend that you take some food and drinks with you for comfort. Passengers are asked for travel documents four times along the way.
An alternative route is also available between Zagreb and Sarajevo which may be of interest.