<p>We're experimenting with following an agile approach to software development where I work.  It's working well so far, however, towards the end of the iteration, we had a problem with a build and it cost a day's worth of time fixing: time that should have been dedicated to testing.</p>

<p>As a result, our QA doesn't have enough time to complete the testing before the end of the iteration.  How do you deal with this scenario - where unforeseen problems impact on tasks during the iteration?</p>

It depends on the scheduling of your QA - can you let them continue testing while developers are working on the next iteration already or not?
If yes, I'd let them finish testing.
Just continue on with the next iteration with the data that you have already.  You really don't want to hold back a number of people because of one bottleneck.  You could add a little extra slack on the next iteration to fix bugs that haven't been reported yet, by assigning slightly less work than a full iteration's worth for every developer.
If no, just plan the next iteration as any normal iteration and test at the end of the iteration as before.