Two unidentified gunmen on a motorcycle opened fire at the check post near Masjid Hurrairah in Karachi's Baldia Ittehad Town, killing three Rangers on the spot and injuring another who later died in a hospital.
Police said that attackers intended to target the Sunni Mosque during Friday prayers, when some 500 people were inside and in the adjoining madrassa.
"The attackers wanted to attack the Mosque during the Friday prayers but on seeing Rangers security, resorted to firing at the personnel," Rangers Director General Major General Bilal Akbar was quoted as saying by the Dawn News.
The area has been sealed by security forces and a search operation is underway.
Ittehad Town, a western suburb of the southern city, is infested with Taliban-linked militants.
The Rangers as well as the police have been engaged in a three-year long anti-militant and crime operation in Karachi and come under attack by militants frequently.