The identities of three of the men matched those in an alert attributed to US officials saying three suspected jihadists were in Central America.
There were fears they could have plans to try to enter the US, reports said.
The four, aged between 26 and 41, included two Egyptians and two Iraqis. They have been deported to Costa Rica.
The men entered Nicaragua through an unauthorised crossing point known as La Guasimada near the southern municipality of Cárdenas, Nicaraguan police said (in Spanish).
They were detained on Tuesday morning local time and deported in the evening.
Islamic State group: The full story
After the caliphate: Has IS been defeated?
Mohamed Ibrahim, 33, and Mahmoud Samy Eissa, 26, both from Egypt, and Iraqi national Ahmed Ghanim Mohamed Al Jubury, 41, arrived in Costa Rica on 9 June, according to their immigration documents given to police.
That date matched the information released in a warning by US Homeland Security Investigations (HSI) published by local media.
Image Copyright @nacion @nacion
When the three entered Costa Rica from Panama, there was no information about possible risks they could pose, Costa Rica's immigration authorities were quoted by La Nación newspaper as saying (in Spanish).
The fourth man was named as 29-year-old Mustafa Ali Mohamed Yaoob from Iraq, who had registered in Costa Rica on 13 June.
The four were being held at a detention facility and would be deported to their countries, La Nación added. No date has been set yet.