A goal from substitute Wiseman Maluleke in the 76th minute saw Cosmos earn the three points which saw them top the play-off league table with seven points, the same as Black Leopards, but with a superior goal difference while Swallows finished bottom on three points.
Cosmos were the better side in the opening half with their first attempt on goal coming in the second minute courtesy of a poor clearance by the Swallows goalkeeper straight to Nkanyiso Madonsela, but the he saw his shot on goal well-saved by Obren Cuckovic who scurried back across the face of his goal
In the 12th minute Cosmos were a dealt a blow when Thato Sithole had to leave the field with a shoulder injury and was replaced by Wiseman Maluleke.
Four minutes later the home side created their first chance on goal when Rudi Isaacs met a cross from the right, but saw his ten-yard header go wide of the goal.
In the 29th minute Charlton Mashumba met a left wing cross with an acrobatic volley, but the Cosmos man saw his attempt go narrowly wide of the post.
Four minutes later Cosmos came close again to opening the scoring when substitute Maluleke fired inches wide of the target from the edge of the box.
In the 42nd minute Swallows were reduced to ten men when Lerato Changabu was harshly shown a straight red card for what the referee deemed a studs-up challenge on Ndabenhle Mthembu.
The match entered the half-time break locked at 0-0.
Cosmos continued to control proceedings in the second half and had their first shot of the stanza in the 49th minute when 24-yard free-kick from Mashumba was well-saved by Cuckovic.
Swallows, despite seeing very little of the ball, did have an attempt on goal on the hour mark when Lantshene Phalane fired a 20-yard free-kick inches over the crossbar.
Cosmos, though, did not let up and saw two substitutes combining in the 76th minute when Pentjie Zulu played Maluleke into space 14-yards out and he made no mistake with a powerful finish to give his side the lead, 1-0.
Cosmos shut-up shop at the back thereafter and held on for the slender win which sees them into the Absa Premiership next season.
Line-ups: