Down to the wire

At the very last moment, very close to the time when something is due (from the wire at the end of a horse race).

The election went down to the wire but the candidate was re-elected to another term in office. We went down to the wire but we were able to finish the project on time.