At the close of the second day, New Zealand were 231 for two, holding a commanding 305-run lead in their second innings with eight wickets in hand.
Sri Lanka's hopes of taking the series-deciding Test were severely dented in a 15-ball masterclass of swing bowling from Boult when he took six wickets for four runs.
It gave New Zealand a 74-run first-innings lead, which Latham and Raval extended to 195 with a century opening stand.
Kane Williamson and Latham added a further 68 for the second wicket until Williamson played a lazy shot to Lahiru Kumara and was caught at first slip for 48.
At the close of the second day, Latham was on 74 with Ross Taylor on 25.
Latham, who starred in the first Test with an unbeaten double century, has faced 213 deliveries.
He received a life on 32 when he top-edged Suranga Lakmal to fine leg where the ball slipped through the fingers of a diving Dushmantha Chameera.
Patel, who worked with Latham to produce the first wicketless session in the Test when they batted from lunch to tea, was out in the second over after the resumption for 74 when he edged Dilruwan Perera to Kusal Mendis at short leg.
Sri Lanka resumed at 88 for four harbouring thoughts of overhauling New Zealand's first innings 178.
But nine overs and 16 runs later their last six wickets were gone, all taken by Boult, who finished with a career best six for 30.
Only Angelo Mathews was able to keep Boult out and he was unbeaten on 33 at the close of the innings.
Boult triggered the collapse when he had Roshen Silva caught by Tim Southee at third slip for 21.
A diving Southee produced a spectacular one-handed catch in Boult's next over to remove Niroshan Dickwella for four.
Dilruwan Perera, Suranga Lakmal, Chameera and Lahiru Kumara all misread Boult and went quickly leg before wicket without scoring to end the innings.
Perera and Lakmal fell in consecutive deliveries with Chameera blocking the next ball to avoid a hat-trick before he was removed with the second ball he faced.
There was movement off the seam for Suranga Lakmal and Kumara when New Zealand began their second innings, but the Sri Lankan quicks did not manage the kind of sudden movement in the air that Boult had found.
First Published: December 27, 2018, 11:18 AM IST