The troubled intercity rail operator will enter public ownership when its contract expires, following years of complaints over delays and cancellations.