Chasing an improbable 413-run victory target in home hero Kumar Sangakkara's farewell test, Sri Lanka resumed on 72-2 but Ashwin and leg-spinner Amit Mishra (3-29) combined to bowl them out for 134 in the second over after an early lunch.
The third and final test will be played in Colombo starting on Friday.
Sri Lanka's day had started badly when they lost their skipper Angelo Mathews to the first delivery of the morning, with Umesh Yadav inducing an edge and India's stand-in wicketkeeper Lokesh Rahul taking a diving catch.
Mathews' exit unhinged the Sri Lankan side who struggled against Ashwin's turn and bounce before collapsing in 43.4 overs.