Hillary Clinton won a largely symbolic victory in the Democratic vote.No delegates are at stake for the Democrats because the state's Democratic Party has been penalised by the national party for breaking rules on when it could hold its primary.
The BBC's Kevin Connolly in Orlando says Mr McCain's win probably makes him a slight front-runner going into Super Tuesday - but the closeness of the margin may also encourage Mr Romney.Observers can expect things to be equally tight on Super Tuesday, our correspondent adds.
With 97% of the vote counted, Mr McCain led Mr Romney by 36% to 31%. The result means Mr McCain will take all 57 delegates in what is a winner-takes-all primary - the biggest prize of the primary season so far.The delegates will attend the party's national convention later this year when the Republican candidate is chosen.
Speaking to cheering supporters at a rally in Miami, Mr McCain said: "Our victory might not have reached landslide proportions, but it was sweet nonetheless." He said he believed he would win the Republican nomination and would go on to win "against anyone the Democratic Party nominates".
"Tonight, my friends, we celebrate but tomorrow it's back to work. We have a ways to go but we are getting close."Mr McCain's Florida victory follows a win for the Arizona senator in South Carolina 10 days ago and another in New Hampshire on 8 January.
In campaigning, Mr McCain focused on national security and had the benefit of strong support among a large number of military servicemen and veterans in the state.Mr Romney, speaking in St Petersburg, Florida, said he had telephoned Mr McCain to offer his congratulations.
A former businessman and ex-governor of Massachusetts, Mr Romney has presented himself as someone with the credentials to shore up the economy.He said he would be appearing at the Republican presidential debate in Simi Valley, California, on Wednesday night.
None of the Democratic candidates campaigned in Florida after the party's national committee penalised Florida for holding its primary early.But Hillary Clinton - who has said she wants the state's delegates reinstated and seated at the national convention - held a victory rally in Davie, Florida, as the results came in.
With 91% of the vote counted, she was winning by 50% to chief rival Barack Obama's 33%, with John Edwards in third with 15%.
She told supporters: "I am thrilled to have had this vote of confidence that you have given me today and I promise you I will do everything I can to make sure not only are Florida's Democratic delegates seated, but Florida is in the winning column for the Democrats in 2008."
Mr Obama told reporters he believed the decision on delegates "should be made after the nomination, not before".Mr Obama spent the day campaigning in Kansas, another Super Tuesday state.He also picked up the endorsement of Kansas Governor Kathleen Sebelius, who delivered the Democratic response to President George W Bush's State of the Union address on Monday.