At stumps on day four, Ireland were 54 for the loss of openers James McCollum (10) and Peter Moor (19) and still 159 runs from making Sri Lanka bat again.
McCollum was brilliantly bowled by offspinner Ramesh Mendis and Moor was dismissed when Angelo Mathews held a superb low catch at short extra cover.
Sri Lanka were pushing for a 100th Test win and a series sweep with the benefit of home advantage and a fifth-day pitch.
Propelled by Madushka's 205 and Mendis' 245, Sri Lanka declared their first innings on 3-705 - a new ground record - immediately after Mathews notched his 15th and fastest century.
The previous highest total at Galle was 638 by Bangladesh in 2013.
Mathews was unbeaten on 100 off 114 balls after hitting four sixes and six boundaries. Dhananjaya de Silva, who replaced an injured Dinesh Chandimal, was 12 not out.
Sri Lanka started the day on 1-357, still 135 runs behind Ireland's first innings total of 492, and batted with complete control.
The first session saw Mendis reach his ninth Test century, and his second in a row against the Irish.
Mendis and Madushka added 132 runs on the morning of day four and seven runs after lunch before Andy McBrine ended their stand by removing Madushka.
The Madushka-Mendis stand was worth 268 runs and Madushka hit 22 boundaries and one six in his nearly eight-hour vigil.
The Irish should have had a third wicket soon after but James McCollum dropped Mathews at midwicket off Graham Hume when he was on one.
While Madushka played a composed innings, Mendis batted ruthlessly, hitting 11 sixes, one short of the world record by Pakistan great Wasim Akram against Zimbabwe, and 17 fours.
Mendis surpassed the previous highest number of sixes by a Sri Lankan - Kumar Sangakkara's eight against Bangladesh in 2014 - and was out at long off going for a 12th six.
Mendis stitched 133 runs for the third wicket with Mathews, who was happy to continue piling up quick runs.
Chandimal was batting on 13 when he injured his right shoulder following a hard landing while diving to the crease. He was taken to hospital for an X-ray.
This is the first time four Sri Lanka batters scored centuries in the same innings, and only the third time in Test history after India and Pakistan. Beside Madushka, Mendis, and Mathews, skipper Dimuth Karunaratne made 115 on day three.
The Irish bowlers were made to toil on an unresponsive pitch where Graham Hume (1-87), Andy McBrine (1-191), and Curtis Campher (1-101) shared the wickets.